Fall out of the hole, because the understanding of the reference type is not deep enough, resulting in a bug in the project.
Let's start with the C # Basics: The reference type assignment assigns the pointer to the object, and the value type assignment is the copy copy, which is one of the differences between the reference type and the value type.
On the code:
1 class Program2 {3 Static voidMain (string[] args)4 {5 varobj =Myclassa.propertya;6Console.WriteLine (string. Join (",", MyClassA.PropertyA.Foo));7Obj. Foo.removeall (M = = m = ="e");8Console.WriteLine (string. Join (",", MyClassA.PropertyA.Foo));9 TenConsole.WriteLine (string. Join (",", MyClassA.PropertyA.Bar)); OneObj. Bar = obj. Bar.where (m = m >2). ToList (); AConsole.WriteLine (string. Join (",", MyClassA.PropertyA.Bar)); - -Obj. Foo =Newlist<string> {"x","y","Z"}; theConsole.WriteLine (string. Join (",", MyClassA.PropertyA.Foo)); - - Console.read (); - } + } - classMyclassa + { A StaticMyclassa () at { -Propertya=NewMYCLASSB (); -Propertya.foo =Newlist<string> {"a","b","C","D","e"}; -Propertya.bar =Newlist<int> {1,2,3,4,5}; - } - Public StaticMYCLASSB Propertya {Get;Private Set; } in } - to classMYCLASSB + { - Publiclist<string> Foo {Get;Set; } the Publiclist<int> Bar {Get;Set; } *}
It is not easy to understand is: I am operating in the internal member of obj, why even Myclassa.propertya member values have been changed?
Because, when Myclassa.propertya is assigned to obj, obj points to Myclassa (reference type), so as long as the operation on the obj member is the internal member of the Operation Mycalssa.
Understanding C # Reference types