SuperLinq SuperLinq
SuperLinq SuperLinq
DocFX + Singulink = ♥

Search Results for

    Method Insert

    | Edit this page

    Insert<T>(IEnumerable<T>, IEnumerable<T>, int)

    Inserts the elements of a sequence into another sequence at a specified index.

    Declaration
    public static IEnumerable<T> Insert<T>(this IEnumerable<T> first, IEnumerable<T> second, int index)
    Parameters
    Type Name Description
    IEnumerable<T> first

    The source sequence.

    IEnumerable<T> second

    The sequence that will be inserted.

    int index

    The zero-based index at which to insert elements from second.

    Returns
    Type Description
    IEnumerable<T>

    A sequence that contains the elements of first plus the elements of second inserted at the given index.

    Type Parameters
    Name Description
    T

    Type of the elements of the source sequence.

    Remarks

    This method uses deferred execution and streams its results.

    Examples

    The following code example demonstrates how to insert one sequence into the middle of another sequence using Insert.

    var first = Enumerable.Range(1, 5);
    var second = Enumerable.Range(1, 5);
                
    // Insert one sequence into another
    var result = first
        .Insert(second, 2);
                
    Console.WriteLine(string.Join(", ", result));
    
    // This code produces the following output:
    // 1, 2, 1, 2, 3, 4, 5, 3, 4, 5
    
    Exceptions
    Type Condition
    ArgumentNullException

    first or second is null.

    ArgumentOutOfRangeException

    Thrown if index is negative.

    ArgumentOutOfRangeException

    Thrown lazily if index is greater than the length of first. The validation occurs when yielding the next element after having iterated first entirely.

    | Edit this page

    Insert<T>(IEnumerable<T>, IEnumerable<T>, Index)

    Inserts the elements of a sequence into another sequence at a specified index.

    Declaration
    public static IEnumerable<T> Insert<T>(this IEnumerable<T> first, IEnumerable<T> second, Index index)
    Parameters
    Type Name Description
    IEnumerable<T> first

    The source sequence.

    IEnumerable<T> second

    The sequence that will be inserted.

    Index index

    The zero-based index at which to insert elements from second.

    Returns
    Type Description
    IEnumerable<T>

    A sequence that contains the elements of first plus the elements of second inserted at the given index.

    Type Parameters
    Name Description
    T

    Type of the elements of the source sequence.

    Remarks

    This method uses deferred execution and streams its results.

    Examples

    The following code example demonstrates how to insert one sequence into the middle of another sequence using Insert.

    var first = Enumerable.Range(1, 5);
    var second = Enumerable.Range(1, 5);
                
    // Insert one sequence into another
    var result = first
        .Insert(second, ^2);
                
    Console.WriteLine(string.Join(", ", result));
    
    // This code produces the following output:
    // 1, 2, 3, 1, 2, 3, 4, 5, 4, 5
    
    Exceptions
    Type Condition
    ArgumentNullException

    first or second is null.

    ArgumentOutOfRangeException

    Thrown if index is negative.

    ArgumentOutOfRangeException

    Thrown lazily if index is greater than the length of first. The validation occurs when yielding the next element after having iterated first entirely.

    © SuperLinq Authors. All rights reserved.