码迷,mamicode.com
首页 > Windows程序 > 详细

C# Distanct

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

标签:line   集合   list   string   style   isa   ring   console   mes   

简单一维集合的使用

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

标签:line   集合   list   string   style   isa   ring   console   mes   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!