Uredi

Deli z drugimi prek


Queryable.CountBy<TSource,TKey> Method

Definition

Returns the count of each element from a sequence according to a specified key selector function.

public static System.Linq.IQueryable<System.Collections.Generic.KeyValuePair<TKey,int>> CountBy<TSource,TKey> (this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,TKey>> keySelector, System.Collections.Generic.IEqualityComparer<TKey>? comparer = default);
static member CountBy : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, 'Key>> * System.Collections.Generic.IEqualityComparer<'Key> -> System.Linq.IQueryable<System.Collections.Generic.KeyValuePair<'Key, int>>
<Extension()>
Public Function CountBy(Of TSource, TKey) (source As IQueryable(Of TSource), keySelector As Expression(Of Func(Of TSource, TKey)), Optional comparer As IEqualityComparer(Of TKey) = Nothing) As IQueryable(Of KeyValuePair(Of TKey, Integer))

Type Parameters

TSource

The type of the elements of source.

TKey

The type of key to distinguish elements by.

Parameters

source
IQueryable<TSource>

The sequence to count elements from.

keySelector
Expression<Func<TSource,TKey>>

A function to extract the key for each element.

comparer
IEqualityComparer<TKey>

An IEqualityComparer<T> to compare keys.

Returns

An IQueryable<T> that contains count for each distinct elements from the source sequence as a KeyValuePair<TKey,TValue> object.

Exceptions

source is null.

Applies to