Table of Contents

Method TopN

Namespace
MongoDB.Driver.Linq
Assembly
MongoDB.Driver.dll

TopN<TSource, TResult>(IEnumerable<TSource>, SortDefinition<TSource>, Func<TSource, TResult>, int)

Returns the top n results.

public static IEnumerable<TResult> TopN<TSource, TResult>(this IEnumerable<TSource> source, SortDefinition<TSource> sortBy, Func<TSource, TResult> selector, int n)

Parameters

source IEnumerable<TSource>

The source.

sortBy SortDefinition<TSource>

The sort order.

selector Func<TSource, TResult>

The selector.

n int

The number of results to return.

Returns

IEnumerable<TResult>

The top n results.

Type Parameters

TSource

The source type.

TResult

The result type.

TopN<TSource, TKey, TResult>(IEnumerable<TSource>, SortDefinition<TSource>, Func<TSource, TResult>, TKey, Func<TKey, int>)

Returns the top n results.

public static IEnumerable<TResult> TopN<TSource, TKey, TResult>(this IEnumerable<TSource> source, SortDefinition<TSource> sortBy, Func<TSource, TResult> selector, TKey key, Func<TKey, int> n)

Parameters

source IEnumerable<TSource>

The source.

sortBy SortDefinition<TSource>

The sort order.

selector Func<TSource, TResult>

The selector.

key TKey

The key (needed to infer the key type and to determine the key serializer).

n Func<TKey, int>

The number of results to return.

Returns

IEnumerable<TResult>

The top n results.

Type Parameters

TSource

The source type.

TKey

The key type.

TResult

The result type.