C # Object Comparisons (value types, reference types)

Source: Internet
Author: User
        Comparison of #region Reference objects///<summary>///Comparison of Reference objects///</summary>//<param name=        "Obja" ></param>//<param name= "OBJB" ></param>//<returns></returns>            public static bool Compareobject (object Obja, Object OBJB) {bool flag = false;            if (Obja = = NULL | | objb = = NULL) {flag = false;            } else if (Obja = = DBNull.Value && objb! = DBNull.Value) {flag = false; } else if (obja! = DBNull.Value && OBJB = = DBNull.Value) {flag = FAL            Se } else if (Obja = = DBNull.Value && OBJB = = DBNull.Value) {//obja objb corresponding column type            The type has been compared with the judged value consistent flag = true;            } else if (obja.gettype () = Objb.gettype ()) {flag = false;           } else if (obja is int | |-Obja is short | | Obja is a long | | Obja is a float | | Obja is a double | | Obja is decimal) { int 01 and 1 if (Obja is int) {if (int) Obja = = (int                    ) {OBJB) {flag = true; }} else if (Obja is short) {if (short) Obja = = (short) OB                    JB) {flag = true;                     }} else if (Obja is long) {if (long) Obja = = (long) OBJB)                    {flag = true; }} else if (Obja is float) {if ((float) Obja = = (float) ob                    JB) {flag = true;            }} else if (Obja is double)    {if (double) Obja = = (double) objb) {flag = true; }} else if (Obja is decimal) {if (decimal                    ) Obja = = (decimal) objb) {flag = true; }}}} else {string stra = metadataxmlserializer<object& gt;.                Toxmlstring (Obja); string StrB = Metadataxmlserializer<object>.                Toxmlstring (OBJB);                if (stra = = StrB) {flag = true;        }} return flag; } #endregion



Small bet

If the two value passed in is the value of a cell in a DataRow, compare the type before calling the method with the same type

Deep Copy Part code:

C # entity class serialization and deserialization one (XmlSerializer)

C # entity class serialization and deserialization two (DatacontractserializeR)

The above is the content of C # object comparison (value type, reference type), please follow topic.alibabacloud.com (www.php.cn) for more related content!

  • 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.