//overwrite Object.Equals() --- reference type realization
public override bool Equals(object _obj)
{
if( _obj==null )
return false;//因为this不可能为null
if( ! (this.GetType()==_obj.GetType()) )
return false;//类型不相等也不相等
Tree tmpObj=(Tree)_obj;
//比较引用成员
if( !Object.Equals(this.Key,tmpObj.Key) )
return false;
//比较值类型成员
if( !this.Degree.Equals(tmpObj.Degree) )
return false;
//if( !this.Height.Equals(tmpObj.Height) )
//return false;
return true;
}
//在此重载 ==,!= 后, 在以后继承的类中不必实现了
public static bool operator==(Tree _treeA,Tree _treeB)
{
return Object.Equals(_treeA,_treeB);
}
public static bool operator!=(Tree _treeA,Tree _treeB)
{
return !(_treeA==_treeB);
}
#region IComparable 成员
public virtual int CompareTo(object obj)
{
// TODO: 添加 Tree.CompareTo 实现
return 0;
}
#endregion
}
}