SuperLinq SuperLinq
SuperLinq SuperLinq
DocFX + Singulink = ♥

Search Results for

    Method ToArrayByIndex

    | Edit this page

    ToArrayByIndex<T>(IEnumerable<T>, Func<T, int>)

    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.

    Declaration
    public static T?[] ToArrayByIndex<T>(this IEnumerable<T> source, Func<T, int> indexSelector)
    Parameters
    Type Name Description
    IEnumerable<T> source

    The source sequence for the array.

    Func<T, int> indexSelector

    A function that maps an element to its index.

    Returns
    Type Description
    T[]

    An array that contains the elements from source. The size of the array will be as large as the highest index returned by the indexSelector plus 1.

    Type Parameters
    Name Description
    T

    The type of the element in source.

    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.

    Examples

    The following code example demonstrates how to transform a sequence into an array using indices using ToArrayByIndex.

    var sequence = new[] { "foo", "bar", "alp", "car", };
    
    // Transform a sequence by index
    var result = sequence
        .ToArrayByIndex(c => c[0] - 'a');
    
    Console.WriteLine(
        "[" +
        string.Join(", ", result) +
        "]");
    
    // This code produces the following output:
    // [alp, bar, car, , , foo]
    
    Exceptions
    Type Condition
    ArgumentNullException

    source or indexSelector is null.

    ArgumentOutOfRangeException

    An index returned by indexSelector is less than 0.

    | Edit this page

    ToArrayByIndex<T, TResult>(IEnumerable<T>, Func<T, int>, Func<T, TResult>)

    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. The elements are projected into the array via an additional function.

    Declaration
    public static TResult?[] ToArrayByIndex<T, TResult>(this IEnumerable<T> source, Func<T, int> indexSelector, Func<T, TResult> resultSelector)
    Parameters
    Type Name Description
    IEnumerable<T> source

    The source sequence for the array.

    Func<T, int> indexSelector

    A function that maps an element to its index.

    Func<T, TResult> resultSelector

    A function to project a source element into an element of the resulting array.

    Returns
    Type Description
    TResult[]

    An array that contains the projected elements from source. The size of the array will be as large as the highest index returned by the indexSelector plus 1.

    Type Parameters
    Name Description
    T

    The type of the element in source.

    TResult

    The type of the element in the resulting array.

    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.

    Examples

    The following code example demonstrates how to transform a sequence into an array using indices using ToArrayByIndex.

    var sequence = new[] { "foo", "bar", "alp", "car", };
    
    // Transform a sequence by index
    var result = sequence
        .ToArrayByIndex(c => c[0] - 'a', c => $"{c[0] - 'a'}:{c}");
    
    Console.WriteLine(
        "[" +
        string.Join(", ", result) +
        "]");
    
    // This code produces the following output:
    // [0:alp, 1:bar, 2:car, , , 5:foo]
    
    Exceptions
    Type Condition
    ArgumentNullException

    source, indexSelector, or resultSelector is null.

    ArgumentOutOfRangeException

    An index returned by indexSelector is less than 0.

    | Edit this page

    ToArrayByIndex<T, TResult>(IEnumerable<T>, Func<T, int>, Func<T, int, TResult>)

    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. The elements are projected into the array via an additional function.

    Declaration
    public static TResult?[] ToArrayByIndex<T, TResult>(this IEnumerable<T> source, Func<T, int> indexSelector, Func<T, int, TResult> resultSelector)
    Parameters
    Type Name Description
    IEnumerable<T> source

    The source sequence for the array.

    Func<T, int> indexSelector

    A function that maps an element to its index.

    Func<T, int, TResult> resultSelector

    A function to project a source element into an element of the resulting array.

    Returns
    Type Description
    TResult[]

    An array that contains the projected elements from source. The size of the array will be as large as the highest index returned by the indexSelector plus 1.

    Type Parameters
    Name Description
    T

    The type of the element in source.

    TResult

    The type of the element in the resulting array.

    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.

    Examples

    The following code example demonstrates how to transform a sequence into an array using indices using ToArrayByIndex.

    var sequence = new[] { "foo", "bar", "alp", "car", };
    
    // Transform a sequence by index
    var result = sequence
        .ToArrayByIndex(c => c[0] - 'a', (c, i) => $"{i}:{c}");
    
    Console.WriteLine(
        "[" +
        string.Join(", ", result) +
        "]");
    
    // This code produces the following output:
    // [0:alp, 1:bar, 2:car, , , 5:foo]
    
    Exceptions
    Type Condition
    ArgumentNullException

    source, indexSelector, or resultSelector is null.

    ArgumentOutOfRangeException

    An index returned by indexSelector is less than 0.

    | Edit this page

    ToArrayByIndex<T>(IEnumerable<T>, int, Func<T, int>)

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

    Declaration
    public static T?[] ToArrayByIndex<T>(this IEnumerable<T> source, int length, Func<T, int> indexSelector)
    Parameters
    Type Name Description
    IEnumerable<T> source

    The source sequence for the array.

    int length

    The (non-negative) length of the resulting array.

    Func<T, int> indexSelector

    A function that maps an element to its index.

    Returns
    Type Description
    T[]

    An array of size length that contains the elements from source.

    Type Parameters
    Name Description
    T

    The type of the element in source.

    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.

    Examples

    The following code example demonstrates how to transform a sequence into an array using indices using ToArrayByIndex.

    var sequence = new[] { "foo", "bar", "alp", "car", };
    
    // Transform a sequence by index
    var result = sequence
        .ToArrayByIndex(26, c => c[0] - 'a');
    
    Console.WriteLine(
        "[" +
        string.Join(", ", result) +
        "]");
    
    // This code produces the following output:
    // [alp, bar, car, , , foo, , , , , , , , , , , , , , , , , , , , ]
    
    Exceptions
    Type Condition
    ArgumentNullException

    source or indexSelector is null.

    ArgumentOutOfRangeException

    length is less than 0. -or- An index returned by indexSelector is invalid for an array of size length.

    | Edit this page

    ToArrayByIndex<T, TResult>(IEnumerable<T>, int, Func<T, int>, Func<T, TResult>)

    Creates an array of user-specified length from an IEnumerable<T> 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.

    Declaration
    public static TResult?[] ToArrayByIndex<T, TResult>(this IEnumerable<T> source, int length, Func<T, int> indexSelector, Func<T, TResult> resultSelector)
    Parameters
    Type Name Description
    IEnumerable<T> source

    The source sequence for the array.

    int length

    The (non-negative) length of the resulting array.

    Func<T, int> indexSelector

    A function that maps an element to its index.

    Func<T, TResult> resultSelector

    A function to project a source element into an element of the resulting array.

    Returns
    Type Description
    TResult[]

    An array of size length that contains the projected elements from source.

    Type Parameters
    Name Description
    T

    The type of the element in source.

    TResult

    The type of the element in the resulting array.

    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.

    Examples

    The following code example demonstrates how to transform a sequence into an array using indices using ToArrayByIndex.

    var sequence = new[] { "foo", "bar", "alp", "car", };
    
    // Transform a sequence by index
    var result = sequence
        .ToArrayByIndex(26, c => c[0] - 'a', (c, i) => $"{i}:{c}");
    
    Console.WriteLine(
        "[" +
        string.Join(", ", result) +
        "]");
    
    // This code produces the following output:
    // [0:alp, 1:bar, 2:car, , , 5:foo, , , , , , , , , , , , , , , , , , , , ]
    
    Exceptions
    Type Condition
    ArgumentNullException

    source, indexSelector, resultSelector is null.

    ArgumentOutOfRangeException

    length is less than 0. -or- An index returned by indexSelector is invalid for an array of size length.

    | Edit this page

    ToArrayByIndex<T, TResult>(IEnumerable<T>, int, Func<T, int>, Func<T, int, TResult>)

    Creates an array of user-specified length from an IEnumerable<T> 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.

    Declaration
    public static TResult?[] ToArrayByIndex<T, TResult>(this IEnumerable<T> source, int length, Func<T, int> indexSelector, Func<T, int, TResult> resultSelector)
    Parameters
    Type Name Description
    IEnumerable<T> source

    The source sequence for the array.

    int length

    The (non-negative) length of the resulting array.

    Func<T, int> indexSelector

    A function that maps an element to its index.

    Func<T, int, TResult> resultSelector

    A function to project a source element into an element of the resulting array.

    Returns
    Type Description
    TResult[]

    An array of size length that contains the projected elements from the input sequence.

    Type Parameters
    Name Description
    T

    The type of the element in source.

    TResult

    The type of the element in the resulting array.

    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.

    Examples

    The following code example demonstrates how to transform a sequence into an array using indices using ToArrayByIndex.

    var sequence = new[] { "foo", "bar", "alp", "car", };
    
    // Transform a sequence by index
    var result = sequence
        .ToArrayByIndex(26, c => c[0] - 'a', c => $"{c[0] - 'a'}:{c}");
    
    Console.WriteLine(
        "[" +
        string.Join(", ", result) +
        "]");
    
    // This code produces the following output:
    // [0:alp, 1:bar, 2:car, , , 5:foo, , , , , , , , , , , , , , , , , , , , ]
    
    Exceptions
    Type Condition
    ArgumentNullException

    source, indexSelector, resultSelector is null.

    ArgumentOutOfRangeException

    length is less than 0. -or- An index returned by indexSelector is invalid for an array of size length.

    © SuperLinq Authors. All rights reserved.