【发布时间】:2011-08-16 01:53:07
【问题描述】:
我想使用自定义泛型类作为字典中的键。我应该如何覆盖Equals 和GetHashCode?
例如,
public class SomeKey<T,V>
{
public T Value1 { get; set; }
public V Value2 { get; set; }
public SomeKey(T val1, V val2)
{
this.Value1 = val1;
this.Value2 = val2;
}
public override bool Equals(SomeKey<T,V> otherKey)
{
//whats the best option here?
}
public override int GetHashCode()
{
//whats the best option here?
}
}
谢谢
【问题讨论】:
标签: c#