首页 > Windows开发 > 详细

C# Distanct

时间:2017-11-06 17:08:09      阅读:219      评论:0      收藏:0      [点我收藏+]

简单一维集合的使用

List<int> ages = new List<int> { 21, 46, 46, 55, 17, 21, 55, 55 };
List<string> names = new List<string> { "wang", "li", "zhang", "li", "wang", "chen", "he", "wang" };

IEnumerable<int> distinctAges = ages.Distinct();
Console.WriteLine("Distinct ages:");
foreach (int age in distinctAges)
{
Console.WriteLine(age);
}

var distinctNames = names.Distinct();
Console.WriteLine("\nDistinct names:");
foreach (string name in distinctNames)
{
Console.WriteLine(name);
}


List<int> ages = new List<int> { 21, 46, 46, 55, 17, 21, 55, 55 };
List<int> disAge = ages.Distinct().ToList(); //除重
foreach (int a in disAge)
Console.WriteLine(a);

C# Distanct

原文:http://www.cnblogs.com/ZkbFighting/p/7794035.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!