Distinct
Distinct去除一个序列里相同的元素。用法如下代码:
static void Main()
{
List<int> ages = new List<int> { 21, 46, 46, 55, 17, 21, 55, 55 };
//Distinct的用法
IEnumerable<int> distinctAges = ages.Distinct();
Console.WriteLine("Distinct ages:");
foreach (int age in distinctAges)
{
Console.WriteLine(age);
}
}
运行结果为:
Distinct ages:
21
46
55
17