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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP