How can we check reference equality for a type that implements equality operator?

前端 未结 2 1027
天命终不由人
天命终不由人 2021-01-26 02:12

In C#, how can we check reference equality for a type that implements equality operator?

class C
{
    public int Val{get;set;}
    public static bool operator =         


        
2条回答
  •  深忆病人
    2021-01-26 02:49

    If you mean equality by reference, you may use the Object.ReferenceEquals static method even if the == operator was overloaded for the current type to work otherwise:

    Object.ReferenceEquals(obj1, obj2);
    

提交回复
热议问题