コード例 #1
0
ファイル: Employee.cs プロジェクト: damonallison/dotnet
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }
            if (ReferenceEquals(this, obj))
            {
                return(true);
            }
            if (this.GetHashCode() != obj.GetHashCode())
            {
                return(false);
            }

            Employee other = (Employee)obj;

            if (!base.Equals(other))
            {
                return(false);
            }
            if (ReferenceEquals(LanId, null))
            {
                return(ReferenceEquals(other.LanId, null));
            }
            return(LanId.Equals(other.LanId));
        }
コード例 #2
0
ファイル: Employee.cs プロジェクト: damonallison/dotnet
        /// <summary>
        /// GetHashCode() should not change over the life of the object. This only works
        /// when values used within the hashCode are immutable. This object does *not*
        /// keep a consistent HashCode over the lifetime of the object since the variables
        /// upon which it's based (Name) is mutable.
        /// </summary>
        public override int GetHashCode()
        {
            int hashCode = base.GetHashCode();
            int prime    = 31;

            hashCode = hashCode * prime + LanId == null ? 0 : LanId.GetHashCode();
            return(hashCode);
        }