PersonInfo类:

    public class PersonInfo
{
public int Index;
public string Name; public override string ToString()
{
return string.Format("Index:{0}, Name:{1}", Index, Name);
}
}

PersonInfoCompareByName比较类:

    public class PersonInfoCompareByName : IEqualityComparer<PersonInfo>
{
public bool Equals(PersonInfo x, PersonInfo y)
{
if (x != null && y != null && x.Name == y.Name)
return true; return false;
} public int GetHashCode(PersonInfo obj)
{
if (obj == null)
{
return ;
}
else
{
return obj.Name.GetHashCode();
}
}
}

下面的代码是新建一个列表,然后去除重复项:

        private void Button_Click(object sender, RoutedEventArgs e)
{
List<PersonInfo> PersonList = new List<PersonInfo>();
for (int i = ; i < ; i++)
{
for (int j = ; j < ; j++)
{
var info = new PersonInfo();
info.Index = j;
info.Name = "Name" + i;
PersonList.Add(info);
}
} var items = PersonList.Distinct(new PersonInfoCompareByName());
foreach (var item in items)
{
Console.WriteLine(item.ToString());
}
}

最新文章

  1. 5.6 JS中基本包装类型
  2. Oracle Tuning 基础概述01 - Oracle 常见等待事件
  3. nodejs笔记
  4. python3 如何使用ip、爬虫
  5. mac攻略(四) -- brew使用
  6. Linux系统编程-setitimer函数
  7. [转]MNIST机器学习入门
  8. IOS-一步一步教你自定义评分星级条RatingBar ——转载的
  9. 共享有线实现手机上网,然后使用charles来抓包
  10. js执行过程
  11. graylog2 架构--转载
  12. 【Qt】Qt环境搭建(Visual Studio)【转】
  13. 003-python列表
  14. IOS流媒体播放
  15. C++使用函数模板
  16. java集合的核心知识
  17. (转)@ContextConfiguration注解说明
  18. php unicode编码和字符串互转
  19. IP的面向无连接状态
  20. ios技术篇:导航栏push遵循的三个规则

热门文章

  1. 阿里云域名和ip绑定步骤
  2. 使用多target来构建大量相似App
  3. Erlang/OTP 中文手册
  4. 通过引入SiteMesh的JSP标签库,解决Freemarker与SiteMesh整合时,自定义SiteMesh标签的问题
  5. 【14.67%】【codeforces 615D】Multipliers
  6. webpack打包不引入vue、echarts等公共库
  7. C# 与.NET2.0 中类型Type的GetMethod方法
  8. 自定义滚动条样式 -webkit-scrollbar
  9. 对偶空间(dual linear space)
  10. 开始使用Material UI