C# Distanct

2021-05-01 03:28

阅读:660

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

简单一维集合的使用

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

IEnumerable 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 ages = new List { 21, 46, 46, 55, 17, 21, 55, 55 };
List 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


评论


亲,登录后才可以留言!