【发布时间】:2011-08-10 13:31:48
【问题描述】:
我有一堂课:
public abstract class AbstractDictionaryObject
{
public virtual int LangId { get; set; }
public override bool Equals(object obj)
{
if (obj == null || obj.GetType() != GetType())
{
return false;
}
AbstractDictionaryObject other = (AbstractDictionaryObject)obj;
if (other.LangId != LangId)
{
return false;
}
return true;
}
public override int GetHashCode()
{
int hashCode = 0;
hashCode = 19 * hashCode + LangId.GetHashCode();
return hashCode;
}
而且我有派生类:
public class Derived1:AbstractDictionaryObject
{...}
public class Derived2:AbstractDictionaryObject
{...}
AbstractDictionaryObject 中只有一个公共字段:LangId。
我认为这不足以(正确地)重载方法。
如何识别对象?
【问题讨论】:
标签: c# overriding equals gethashcode