20141212--c# Object Comparison

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.