MoreEnumerableDistinctByTSource, TKey(IEnumerableTSource, FuncTSource, TKey) Method

Returns all distinct elements of the given source, where "distinctness" is determined via a projection and the default equality comparer for the projected type.

Definition

Namespace: MoreLinq
Assembly: MoreLinq (in MoreLinq.dll) Version: 4.1.0+0e154ef592f33ce0f6f3d534a9eedee273f0ce72
C#
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(
	IEnumerable<TSource> source,
	Func<TSource, TKey> keySelector
)

Parameters

source  IEnumerableTSource
Source sequence
keySelector  FuncTSource, TKey
Projection for determining "distinctness"

Type Parameters

TSource
Type of the source sequence
TKey
Type of the projected element

Return Value

IEnumerableTSource
A sequence consisting of distinct elements from the source sequence, comparing them by the specified key projection.

Remarks

This operator uses deferred execution and streams the results, although a set of already-seen keys is retained. If a key is seen multiple times, only the first element with that key is returned.

See Also