순서를 설정하고 요소를 추가하십시오.
List<int> ID = new List<int> { 120, 111, 250, 111, 120, 300, 399, 450 }; Distinct() 메서드를 사용하여 위 목록에서 고유한 요소를 가져옵니다.
IEnumerable<int> res = ID.AsQueryable().Distinct();
전체 코드를 살펴보겠습니다.
예시
using System;
using System.Linq;
using System.Collections.Generic;
class Demo {
static void Main() {
List<int> ID = new List<int> { 120, 111, 250, 111, 120, 300, 399, 450 };
// get distinct elements
IEnumerable<int> res = ID.AsQueryable().Distinct();
foreach (int arr in res) {
Console.WriteLine(arr);
}
}
} 출력
120 111 250 300 399 450