MoreEnumerable.ToArrayByIndex<T> Method (IEnumerable<T>, Func<T, Int32>) |
Creates an array from an
IEnumerable< T> 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: 2.10.0
Syntaxpublic static T[] ToArrayByIndex<T>(
this IEnumerable<T> source,
Func<T, int> indexSelector
)
<ExtensionAttribute>
Public Shared Function ToArrayByIndex(Of T) (
source As IEnumerable(Of T),
indexSelector As Func(Of T, Integer)
) As T()
public:
[ExtensionAttribute]
generic<typename T>
static array<T>^ ToArrayByIndex(
IEnumerable<T>^ source,
Func<T, int>^ indexSelector
)
[<ExtensionAttribute>]
static member ToArrayByIndex :
source : IEnumerable<'T> *
indexSelector : Func<'T, int> -> 'T[]
Parameters
- source
- Type: System.Collections.Generic.IEnumerable<T>
The source sequence for the array. - indexSelector
- Type: System.Func<T, 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 that contains the 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
IEnumerable<T>. 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