Click or drag to resize

MoreEnumerableToArrayByIndexT, TResult Method (IEnumerableT, FuncT, Int32, FuncT, TResult)

Creates an array from an IEnumerableT where a function is used to determine the index at which an element will be placed in the array. The elements are projected into the array via an additional function.

Namespace:  MoreLinq
Assembly:  MoreLinq (in MoreLinq.dll) Version: 3.0.0
Syntax
public static TResult[] ToArrayByIndex<T, TResult>(
	this IEnumerable<T> source,
	Func<T, int> indexSelector,
	Func<T, TResult> resultSelector
)

Parameters

source
Type: System.Collections.GenericIEnumerableT
The source sequence for the array.
indexSelector
Type: SystemFuncT, Int32
A function that maps an element to its index.
resultSelector
Type: SystemFuncT, TResult
A function to project a source element into an element of the resulting array.

Type Parameters

T
The type of the element in source.
TResult
The type of the element in the resulting array.

Return Value

Type: TResult
An array that contains the projected elements from the input sequence. The size of the array will be as large as the highest index returned by the indexSelector plus 1.

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