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