c# How to find if two objects are equal

前端 未结 6 1951
北荒
北荒 2020-12-08 02:40

I want to know the best way to compare two objects and to find out if they\'re equal. I\'m overriding both GethashCode and Equals. So a basic class looks like:



        
6条回答
  •  醉梦人生
    2020-12-08 03:21

    wouldn't a function Equals always test only against the same type, shouldn't it be:

    //override
        public bool Equals(Test other)//(object obj) 
        {
            //return GetHashCode() == obj.GetHashCode();
            return (Value == other.Value) &&
                   (String1 == other.String1) &&
                   (String2 == other.String2);
        }
    

    regards Oops

提交回复
热议问题