Click or drag to resize
Accord.NET (logo) SortNthElementT Method (T, Int32, Boolean)
Retrieves the n-th smallest element in an array. As a side-effect, partially orders the collection, making sure every element smaller than the n-th smaller element are in the beginning of the array.

Namespace:  Accord
Assembly:  Accord.Math (in Accord.Math.dll) Version: 3.4.0
Syntax
public static T NthElement<T>(
	this T[] items,
	int n,
	bool asc = true
)
where T : Object, IComparable<T>
Request Example View Source

Parameters

items
Type: T
The array of elements from which the n-th element should be extracted.
n
Type: SystemInt32
The position to look for (0 returns the smallest element, 1 the second smallest, and so on).
asc (Optional)
Type: SystemBoolean
Whether to take the smallest or the largest element. If set to false, instead of returning the smallest, the method will return the largest elements.

Type Parameters

T
The type for the items in the array.

Return Value

Type: T
If asc is true, returns the n-th smallest element in the array. Otherwise, returns the n-th largest.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type . 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