using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace rand
{
class Program
{
class E
{
public int a;
public int b;
public E(int aa, int bb)
{
a = aa;
b = bb;
}
public override bool Equals(object obj)
{
E e = obj as E;
return this.a == e.a && this.b == e.b;
}
public override int GetHashCode()
{
return a * 100 + b;
}
}
static void Main(string[] args)
{
HashSet<E> l = new HashSet<E>();
E A = new E(1, 2);
E B = new E(1, 2);
l.Add (A);
l.Add (B);
Console.WriteLine(l.Count);
Console.ReadLine();
}
}
}
c#---HashSet对类的判重
最新推荐文章于 2024-07-02 16:02:25 发布