Click or drag to resize

MongoEnumerableTopNTSource, TKey, TResult Method (IEnumerableTSource, SortDefinitionTSource, FuncTSource, TResult, TKey, FuncTKey, Int32)

Returns the top n results.

Namespace:  MongoDB.Driver.Linq
Assembly:  MongoDB.Driver (in MongoDB.Driver.dll) Version: 2.19.1+3a2a09dd959482f665ffbb5df2557ec541597af4
Syntax
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
Type: System.Collections.GenericIEnumerableTSource
The source.
sortBy
Type: MongoDB.DriverSortDefinitionTSource
The sort order.
selector
Type: SystemFuncTSource, TResult
The selector.
key
Type: TKey
The key (needed to infer the key type and to determine the key serializer).
n
Type: SystemFuncTKey, Int32
The number of results to return.

Type Parameters

TSource
The source type.
TKey
The key type.
TResult
The result type.

Return Value

Type: IEnumerableTResult
The top n results.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableTSource. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
See Also