Enumerable.DistinctBy Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
| Name | Description |
|---|---|
|
DistinctBy |
Returns distinct elements from a sequence according to a specified key selector function. |
|
DistinctBy |
Returns distinct elements from a sequence according to a specified key selector function and using a specified comparer to compare keys. |
DistinctBy(IEnumerable, Func)
- Source:
- Distinct.cs
- Source:
- Distinct.cs
- Source:
- Distinct.cs
- Source:
- Distinct.cs
- Source:
- Distinct.cs
Returns distinct elements from a sequence according to a specified key selector function.
public:
generic
[System::Runtime::CompilerServices::Extension]
static System::Collections::Generic::IEnumerable ^ DistinctBy(System::Collections::Generic::IEnumerable ^ source, Func ^ keySelector);
public static System.Collections.Generic.IEnumerable DistinctBy(this System.Collections.Generic.IEnumerable source, Func keySelector);
static member DistinctBy : seq<'Source> * Func<'Source, 'Key> -> seq<'Source>
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
The sequence to remove duplicate elements from.
- keySelector
-
Func
A function to extract the key for each element.
Returns
An IEnumerable
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
See also
Applies to
DistinctBy(IEnumerable, Func, IEqualityComparer)
- Source:
- Distinct.cs
- Source:
- Distinct.cs
- 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
[System::Runtime::CompilerServices::Extension]
static System::Collections::Generic::IEnumerable ^ DistinctBy(System::Collections::Generic::IEnumerable ^ source, Func ^ keySelector, System::Collections::Generic::IEqualityComparer ^ comparer);
public static System.Collections.Generic.IEnumerable DistinctBy(this System.Collections.Generic.IEnumerable source, Func keySelector, System.Collections.Generic.IEqualityComparer? comparer);
static member DistinctBy : seq<'Source> * Func<'Source, 'Key> * System.Collections.Generic.IEqualityComparer<'Key> -> seq<'Source>
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
The sequence to remove duplicate elements from.
- keySelector
-
Func
A function to extract the key for each element.
- comparer
-
IEqualityComparer
An IEqualityComparer
Returns
An IEnumerable
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 DistinctBycomparer is null, the default equality comparer, Default, is used to compare values.