Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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.
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. |
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)
The type of the elements of source
.
The type of key to distinguish elements by.
The sequence to remove duplicate elements from.
A function to extract the key for each element.
An IEnumerable<T> that contains distinct elements from the source sequence.
source
is null
.
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.
Product | Versions |
---|---|
.NET | 6, 7, 8, 9, 10 |
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)
The type of the elements of source
.
The type of key to distinguish elements by.
The sequence to remove duplicate elements from.
A function to extract the key for each element.
An IEqualityComparer<T> to compare keys.
An IEnumerable<T> that contains distinct elements from the source sequence.
source
is null
.
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.
Product | Versions |
---|---|
.NET | 6, 7, 8, 9, 10 |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in