ListDistinct 过滤

public class TestDuplicateDefine : IEqualityComparer<student>
{
public bool Equals(student x, student y)
{
return x.name == y.name;
} public int GetHashCode(student obj)
{
return obj.ToString().GetHashCode();
}
} public class student
{
public string name { get; set; }
public int id { get; set; }
}
private void button1_Click(object sender, EventArgs e)
{
List<student> list = new List<student>();
list.Add(new student { name = "", id = });
list.Add(new student { name = "", id = });
list.Add(new student { name = "", id = });
list.Add(new student { name = "", id = }); List<student> aa = list.Distinct(new TestDuplicateDefine()).ToList();
}
上一篇:码表 ASCII Unicode GBK UTF-8


下一篇:使用JavaScript实现简单的双色球