Static voidMain (string[] args) {Class2 oo=NewClass2 (); Oo.shu=101; Oo.zi="You're"; Class2 SS=NewClass2 (); BOOLBL = OO = = SS;//When you compare two objects directly, they are two different objects, regardless of whether the values are equal. Console.WriteLine (BL); SS= OO;//directly causes two objects to be equal, pointing to the same object, (two different indexes). BOOLbr = OO = =SS; Console.WriteLine (BR); Console.WriteLine (Oo.zi); Ss.zi="I'm"; Console.WriteLine (Oo.zi); Console.ReadLine (); }
// another class created by Class2 namespace fengzhuang{ class Class2 { publicint shu; Publicstring zi;} }
Create according to the code above.
Create two objects, (initialize)
If you let these two objects directly compare, regardless of their value, it is two different objects.
If you make two objects equal, you point to an object, like a shortcut,
By comparing the values within two objects, the two values are compared.
When you create two objects, it is equivalent to opening up two different spatial locations, which cannot be the same two objects. In writing the equation: Object 1 = object 2; (When an object is directly equal to another object) is to have an object with two different indexes, which is equivalent to creating only one space, regardless of which index is found, will find the same space, if modified, and then viewed with other indexes, All you see is the modified space.
20141212--c# Object Comparison