C# containers initialized by reference or value?
问题 I'm experienced with C++, but a little new to C#. When you add objects to a container, are they passed by reference or by value? That is, if I do this: myClass m = new myClass(0); //Assume the class just holds an int List<myClass> myList = new List<myClass>(1); myList.Add(m); myList[0] += 1; Console.WriteLine(m); Console.WriteLine(myList[0]); Will the result be: 0 1 or will it be 1 1 ? If the former, then how can get I make it do the latter? My first instinct was to do something like myClass