Click or drag to resize

MoreEnumerableToArrayByIndexT Method (IEnumerableT, Int32, FuncT, Int32)

Creates an array of user-specified length from an IEnumerableT where a function is used to determine the index at which an element will be placed in the array.

Namespace:  MoreLinq
Assembly:  MoreLinq (in MoreLinq.dll) Version: 3.3.1+b77df70598ab84c28cd43dcf74594024b6d575e1
Syntax
public static T[] ToArrayByIndex<T>(
	this IEnumerable<T> source,
	int length,
	Func<T, int> indexSelector
)

Parameters

source
Type: System.Collections.GenericIEnumerableT
The source sequence for the array.
length
Type: SystemInt32
The (non-negative) length of the resulting array.
indexSelector
Type: SystemFuncT, Int32
A function that maps an element to its index.

Type Parameters

T
The type of the element in source.

Return Value

Type: T
An array of size length that contains the elements from the input sequence.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableT. 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).
Remarks
This method forces immediate query evaluation. It should not be used on infinite sequences. If more than one element maps to the same index then the latter element overwrites the former in the resulting array.
See Also