C # exploring equality judgment,
C # method for Equality judgment:
// Determine whether the specified System. Object is equal to the current System. Object
Public virtual bool Equals (object obj) {return RuntimeHelpers. equals (this, obj);} // determine whether to set the specified System. the Object instance is treated as equal public static bool Equals (object objA, object objB) {return (objA = objB) | (objA! = Null) & (objB! = Null) & objA. equals (objB);} // determine the specified System. whether the Object instance is the same instance public static bool ReferenceEquals (object objA, object objB) {return (objA = objB );}
= And! = Operator comparison content
**************************************** **************************************** **************************************
Using System; using System. collections; using System. collections. generic; using System. linq; using System. text; namespace ValueTypeDemo {// Shoes class {private string name; // product Name private int price; // unit price public string name {get {return name ;} set {name = value ;}} public int Price {get {return price;} set {price = value ;}}} class Program {static void Main (string [] args) {Shoes S1 = new Shoes (); Shoes S2 = new Shoes (); Shoes S3 = S2; int x = 5; int y = 8; int z = x; object A = 11; object B = A; object C = 11; // content comparison Console. writeLine (x = y); // false Console. writeLine (x = z); // true // compare Console by reference after packing. writeLine (A = B); // true Console. writeLine (A = C); // false // After packing, compare the values before packing to determine whether the Console is equal. writeLine (. equals (B); // true Console. writeLine (. equals (C); // true Console. writeLine (Equals (A, B); // true Console. writeLine (Equals (A, C); // true // force compare Console by reference. writeLine (ReferenceEquals (A, B); // true Console. writeLine (ReferenceEquals (A, C); // false Console. readKey ();}}}