namespace ConsoleApplication3
{
class Age
{
private int _year;
public Age(int year)
{
_year = year;
}
public int Year
{
get
{
return this._year;
}
}
public override bool Equals(object obj)
{
Age a = (Age)obj;
return a._year == this._year;
}
public override int GetHashCode()
{
return base.GetHashCode() ^ _year;
}
}
class Program
{
static void Main(string[] args)
{
System.Collections.Hashtable ageList = new System.Collections.Hashtable();
Age a1 = new Age(123);//其中a1和a3拥有相同的值。
ageList.Add(a1, a1);
Age a2 = new Age(567);
ageList.Add(a2,a2);