日期:2014-05-16 浏览次数:20728 次
class c
{
public static int i = 0;
public int GetHashCode() { return i++; }
}
Console.WriteLine(obj1 != obj2);
class C
{
public static int i = 0;
public override int GetHashCode() { return i++; }
}
static void Main(string[] args)
{
C obj1 = new C();
HashSet<C> hashSet = new HashSet<C>(new C[] { obj1, obj1 });
int count = hashSet.Count; // 2 (如果把GetHashCode override去掉,就是1)
}