相关疑难解决方法(0)

IEquatable接口检查null时要做什么

我已经使用以下代码在类中实现了IEquatable接口.

        public bool Equals(ClauseBE other)
        {
            if (this._id == other._id)
            {
                return true;
            }
            return false;
        }

        public override bool Equals(Object obj)
        {
            if (obj == null)
            {
                return base.Equals(obj);
            }

            if (!(obj is ClauseBE))
            {
                throw new InvalidCastException("The 'obj' argument is not a ClauseBE object.");
            }

            return Equals(obj as ClauseBE);
        }

        public override int GetHashCode()
        {
            return this._id.GetHashCode();
        }

        public static bool operator ==(ClauseBE a, ClauseBE b)
        {
            // cast to object so we call the overloaded Equals function …
Run Code Online (Sandbox Code Playgroud)

c# iequatable

6
推荐指数
1
解决办法
3625
查看次数

标签 统计

c# ×1

iequatable ×1