CollectionExtensions.DistinctBy Method

Namespace:
Weavy.Core.Helpers
Assembly:
Weavy.Core.dll

DistinctBy(IEnumerable, Func)

Returns all distinct elements of the given source, where "distinctness" is determined via a projection and the default equality comparer for the projected type, e.g. var distinct = list.DistinctBy(x => x.ID).

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.

public static IEnumerable DistinctBy(this IEnumerable source, Func selector)

Parameters

source
System.Collections.Generic.IEnumerable{{TSource}}
selector
System.Func{{TSource},{TKey}}

Returns

System.Collections.Generic.IEnumerable{{TSource}}

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