Editare

Partajați prin


Enumerable.DistinctBy Method

Definition

Overloads

DistinctBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)

Returns distinct elements from a sequence according to a specified key selector function.

DistinctBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

Returns distinct elements from a sequence according to a specified key selector function and using a specified comparer to compare keys.

DistinctBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)

Source:
Distinct.cs
Source:
Distinct.cs
Source:
Distinct.cs

Returns distinct elements from a sequence according to a specified key selector function.

public:
generic <typename TSource, typename TKey>
[System::Runtime::CompilerServices::Extension]
 static System::Collections::Generic::IEnumerable<TSource> ^ DistinctBy(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, TKey> ^ keySelector);
public static System.Collections.Generic.IEnumerable<TSource> DistinctBy<TSource,TKey> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,TKey> keySelector);
static member DistinctBy : seq<'Source> * Func<'Source, 'Key> -> seq<'Source>
<Extension()>
Public Function DistinctBy(Of TSource, TKey) (source As IEnumerable(Of TSource), keySelector As Func(Of TSource, TKey)) As IEnumerable(Of TSource)

Type Parameters

TSource

The type of the elements of source.

TKey

The type of key to distinguish elements by.

Parameters

source
IEnumerable<TSource>

The sequence to remove duplicate elements from.

keySelector
Func<TSource,TKey>

A function to extract the key for each element.

Returns

IEnumerable<TSource>

An IEnumerable<T> that contains distinct elements from the source sequence.

Exceptions

source is null.

Remarks

This method is implemented by using deferred execution. The immediate return value is an object that stores all the information that is required to perform the action. The query represented by this method is not executed until the object is enumerated either by calling its GetEnumerator method directly or by using foreach in C# or For Each in Visual Basic.

The DistinctBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>) method returns an unordered sequence that contains no duplicate values. The default equality comparer, Default, is used to compare values.

See also

Applies to

DistinctBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

Source:
Distinct.cs
Source:
Distinct.cs
Source:
Distinct.cs

Returns distinct elements from a sequence according to a specified key selector function and using a specified comparer to compare keys.

public:
generic <typename TSource, typename TKey>
[System::Runtime::CompilerServices::Extension]
 static System::Collections::Generic::IEnumerable<TSource> ^ DistinctBy(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, TKey> ^ keySelector, System::Collections::Generic::IEqualityComparer<TKey> ^ comparer);
public static System.Collections.Generic.IEnumerable<TSource> DistinctBy<TSource,TKey> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,TKey> keySelector, System.Collections.Generic.IEqualityComparer<TKey>? comparer);
static member DistinctBy : seq<'Source> * Func<'Source, 'Key> * System.Collections.Generic.IEqualityComparer<'Key> -> seq<'Source>
<Extension()>
Public Function DistinctBy(Of TSource, TKey) (source As IEnumerable(Of TSource), keySelector As Func(Of TSource, TKey), comparer As IEqualityComparer(Of TKey)) As IEnumerable(Of TSource)

Type Parameters

TSource

The type of the elements of source.

TKey

The type of key to distinguish elements by.

Parameters

source
IEnumerable<TSource>

The sequence to remove duplicate elements from.

keySelector
Func<TSource,TKey>

A function to extract the key for each element.

comparer
IEqualityComparer<TKey>

An IEqualityComparer<T> to compare keys.

Returns

IEnumerable<TSource>

An IEnumerable<T> that contains distinct elements from the source sequence.

Exceptions

source is null.

Remarks

This method is implemented by using deferred execution. The immediate return value is an object that stores all the information that is required to perform the action. The query represented by this method is not executed until the object is enumerated either by calling its GetEnumerator method directly or by using foreach in C# or For Each in Visual Basic.

The DistinctBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>) method returns an unordered sequence that contains no duplicate values. If comparer is null, the default equality comparer, Default, is used to compare values.

See also

Applies to