C# HowTo 重写Equals和GetHashCode

直接上码:

    public class MyObject
    {
        public string name;

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != this.GetType()) return false;
            return ((MyObject)obj).name == this.name;
        }

        public override int GetHashCode()
        {
            return (name != null ? name.GetHashCode() : 0);
        }
    }

 

C# HowTo 重写Equals和GetHashCode

上一篇:Windows Phone 8.1 与 Windows Phone 8.1 Silverlight区别


下一篇:PHP-Windows下搭建Nginx+PHP环境