C#Linq Distinct()方法
若要获取不同的元素,请使用Distinct()方法。
以下是包含重复元素的列表。
List<int> points = new List<int> { 5, 10, 5, 20, 30, 30, 40, 50, 60, 70 };现在获取不同的元素-
points.AsQueryable().Distinct();
让我们看整个例子-
示例
using System;
using System.Linq;
using System.Collections.Generic;
class Demo {
static void Main() {
List<int> points = new List<int> { 5, 10, 5, 20, 30, 30, 40, 50, 60, 70 };
// distict elements from the list
IEnumerable<int> res = points.AsQueryable().Distinct();
foreach (int a in res) {
Console.WriteLine(a);
}
}
}输出结果
5 10 20 30 40 50 60 70
热门推荐
4 奥运会简短祝福语
10 英文祝福语简短离别伤感
11 别人生产祝福语简短
12 教师高考祝福语霸气简短
13 阳光句子简短祝福语男生
14 酒店送水果祝福语简短
15 准爸爸生日祝福语简短
16 婚庆公司婚礼祝福语简短
17 祝福语简短幽默的句子
18 自家新车的祝福语简短