复制代码 代码如下:
public static bool Equals(object objA, object objB)
{
return ((objA == objB) || (((objA != null) && (objB != null)) && objA.Equals(objB)));
}
public virtual bool Equals(object obj)
{
return InternalEquals(this, obj);
}
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool InternalEquals(object objA, object objB);
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static bool ReferenceEquals(object objA, object objB)
{
return (objA == objB);
}
复制代码 代码如下:
class Program
{
static void Main(string[] args)
{
//AAA a1 = new AAA { Name = "a1", Age = 22 };
//AAA a2 = new AAA { Name = "a1", Age = 22 };
//int a1 = 123;
//int a2 = 123;
string a1 = "abc";
string a2 = "abc";
Console.WriteLine(string.Format("==: {0}", a1 == a2));
Console.WriteLine(string.Format("Equals: {0}", a1.Equals(a2)));
Console.WriteLine(string.Format("Static Equals: {0}", Object.Equals(a1, a2)));
Console.WriteLine(string.Format("ReferenceEquals: {0}", ReferenceEquals(a1, a2)));
Console.Read();
}
}
// Class or Struct
struct AAA
{
public string Name { get; set; }
public int Age { get; set; }
}
新闻热点
疑难解答
图片精选