I'm working on quite a complex project and have been struggling to debug one problem for the last hour. I nailed down the troublesome code which looks more or less like this:
Client ClientToChange = Clients[index];
ClientToChange.Rank = 80;
Clients is a static array of classes Client, declared in the same class.
Changing ClientToChange's rank for some reason alters the contents of the array, i.e.
Console.WriteLine(Clients[index].Rank)
returns 80 (whereas before it was 100), of course index
was not changed.
This seems bizarre to me, but that's what happens.
I wrote a little dummy program to test this out, just to make sure:
static string[] foo = new string[10];
static void Main(string[] args)
{
foo[3] = "bar";
string test = "";
test = foo[3];
test = "fb";
Console.Write(foo[3]);
Console.Write(test);
This, of course, works like it should: prints barfb.
Am I doing something that I cannot see, or I don't know something I should?