Queryable.Distinct 메서드

정의

시퀀스의 고유 요소를 반환합니다.Returns distinct elements from a sequence.

오버로드

Distinct<TSource>(IQueryable<TSource>)

기본 같음 비교자로 값을 비교하여 시퀀스에서 고유 요소를 반환합니다.Returns distinct elements from a sequence by using the default equality comparer to compare values.

Distinct<TSource>(IQueryable<TSource>, IEqualityComparer<TSource>)

지정된 IEqualityComparer<T>로 값을 비교하여 시퀀스에서 고유 요소를 반환합니다.Returns distinct elements from a sequence by using a specified IEqualityComparer<T> to compare values.

Distinct<TSource>(IQueryable<TSource>)

기본 같음 비교자로 값을 비교하여 시퀀스에서 고유 요소를 반환합니다.Returns distinct elements from a sequence by using the default equality comparer to compare values.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static System::Linq::IQueryable<TSource> ^ Distinct(System::Linq::IQueryable<TSource> ^ source);
public static System.Linq.IQueryable<TSource> Distinct<TSource> (this System.Linq.IQueryable<TSource> source);
static member Distinct : System.Linq.IQueryable<'Source> -> System.Linq.IQueryable<'Source>
<Extension()>
Public Function Distinct(Of TSource) (source As IQueryable(Of TSource)) As IQueryable(Of TSource)

형식 매개 변수

TSource

source 요소의 형식입니다.The type of the elements of source.

매개 변수

source
IQueryable<TSource>

중복을 제거할 IQueryable<T>입니다.The IQueryable<T> to remove duplicates from.

반환

IQueryable<TSource>

source의 고유 요소가 들어 있는 IQueryable<T>입니다.An IQueryable<T> that contains distinct elements from source.

예외

source이(가) null인 경우source is null.

예제

다음 코드 예제에서는를 사용 하 여 Distinct<TSource>(IQueryable<TSource>) 시퀀스에서 고유 요소를 반환 하는 방법을 보여 줍니다.The following code example demonstrates how to use Distinct<TSource>(IQueryable<TSource>) to return distinct elements from a sequence.

List<int> ages = new List<int> { 21, 46, 46, 55, 17, 21, 55, 55 };

IEnumerable<int> distinctAges = ages.AsQueryable().Distinct();

Console.WriteLine("Distinct ages:");

foreach (int age in distinctAges)
    Console.WriteLine(age);

/*
    This code produces the following output:

    Distinct ages:
    21
    46
    55
    17
*/
Dim ages As List(Of Integer) = New List(Of Integer)(New Integer() {21, 46, 46, 55, 17, 21, 55, 55})

Dim distinctAges As IEnumerable(Of Integer) = ages.AsQueryable().Distinct()

Dim output As New System.Text.StringBuilder
output.AppendLine("Distinct ages:")

For Each age As Integer In distinctAges
    output.AppendLine(age)
Next

' Display the output.
MsgBox(output.ToString())

' This code produces the following output:
'
' Distinct(ages)
' 21
' 46
' 55
' 17

설명

Distinct<TSource>(IQueryable<TSource>)메서드는 자신을 MethodCallExpression 생성 된 제네릭 메서드로 호출 하는을 생성 합니다 Distinct<TSource>(IQueryable<TSource>) .The Distinct<TSource>(IQueryable<TSource>) method generates a MethodCallExpression that represents calling Distinct<TSource>(IQueryable<TSource>) itself as a constructed generic method. 그런 다음 MethodCallExpression CreateQuery<TElement>(Expression) IQueryProvider Provider 매개 변수의 속성이 나타내는의 메서드에를 전달 합니다 source .It then passes the MethodCallExpression to the CreateQuery<TElement>(Expression) method of the IQueryProvider represented by the Provider property of the source parameter.

호출을 나타내는 식 트리를 실행 한 결과로 발생 하는 쿼리 동작은 Distinct<TSource>(IQueryable<TSource>) 매개 변수의 형식 구현에 따라 달라 집니다 source .The query behavior that occurs as a result of executing an expression tree that represents calling Distinct<TSource>(IQueryable<TSource>) depends on the implementation of the type of the source parameter. 예상 되는 동작은에서 순서가 지정 되지 않은 고유 항목 시퀀스를 반환 한다는 것입니다 source .The expected behavior is that it returns an unordered sequence of the unique items in source.

적용 대상

Distinct<TSource>(IQueryable<TSource>, IEqualityComparer<TSource>)

지정된 IEqualityComparer<T>로 값을 비교하여 시퀀스에서 고유 요소를 반환합니다.Returns distinct elements from a sequence by using a specified IEqualityComparer<T> to compare values.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static System::Linq::IQueryable<TSource> ^ Distinct(System::Linq::IQueryable<TSource> ^ source, System::Collections::Generic::IEqualityComparer<TSource> ^ comparer);
public static System.Linq.IQueryable<TSource> Distinct<TSource> (this System.Linq.IQueryable<TSource> source, System.Collections.Generic.IEqualityComparer<TSource> comparer);
public static System.Linq.IQueryable<TSource> Distinct<TSource> (this System.Linq.IQueryable<TSource> source, System.Collections.Generic.IEqualityComparer<TSource>? comparer);
static member Distinct : System.Linq.IQueryable<'Source> * System.Collections.Generic.IEqualityComparer<'Source> -> System.Linq.IQueryable<'Source>
<Extension()>
Public Function Distinct(Of TSource) (source As IQueryable(Of TSource), comparer As IEqualityComparer(Of TSource)) As IQueryable(Of TSource)

형식 매개 변수

TSource

source 요소의 형식입니다.The type of the elements of source.

매개 변수

source
IQueryable<TSource>

중복을 제거할 IQueryable<T>입니다.The IQueryable<T> to remove duplicates from.

comparer
IEqualityComparer<TSource>

값을 비교할 IEqualityComparer<T>입니다.An IEqualityComparer<T> to compare values.

반환

IQueryable<TSource>

source의 고유 요소가 들어 있는 IQueryable<T>입니다.An IQueryable<T> that contains distinct elements from source.

예외

source 또는 comparernull인 경우source or comparer is null.

설명

Distinct<TSource>(IQueryable<TSource>, IEqualityComparer<TSource>)메서드는 자신을 MethodCallExpression 생성 된 제네릭 메서드로 호출 하는을 생성 합니다 Distinct<TSource>(IQueryable<TSource>, IEqualityComparer<TSource>) .The Distinct<TSource>(IQueryable<TSource>, IEqualityComparer<TSource>) method generates a MethodCallExpression that represents calling Distinct<TSource>(IQueryable<TSource>, IEqualityComparer<TSource>) itself as a constructed generic method. 그런 다음 MethodCallExpression CreateQuery<TElement>(Expression) IQueryProvider Provider 매개 변수의 속성이 나타내는의 메서드에를 전달 합니다 source .It then passes the MethodCallExpression to the CreateQuery<TElement>(Expression) method of the IQueryProvider represented by the Provider property of the source parameter.

호출을 나타내는 식 트리를 실행 한 결과로 발생 하는 쿼리 동작은 Distinct<TSource>(IQueryable<TSource>, IEqualityComparer<TSource>) 매개 변수의 형식 구현에 따라 달라 집니다 source .The query behavior that occurs as a result of executing an expression tree that represents calling Distinct<TSource>(IQueryable<TSource>, IEqualityComparer<TSource>) depends on the implementation of the type of the source parameter. 예상 되는 동작은를 사용 하 여 값을 비교 하 여에서 순서가 지정 되지 않은 고유 항목 시퀀스를 반환 한다는 것입니다 source comparer .The expected behavior is that it returns an unordered sequence of the unique items in source by using comparer to compare values.

적용 대상