SuperLinq SuperLinq
SuperLinq SuperLinq
DocFX + Singulink = ♥

Search Results for

    Method Backsert

    | Edit this page

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

    Inserts the elements of a sequence into another sequence at a specified index from the tail of the sequence, where zero always represents the last position, one represents the second-last element, two represents the third-last element and so on.

    Declaration
    [Obsolete("Backsert has been replaced by Insert(second, Index index)")]
    public static IEnumerable<T> Backsert<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 from the end of first where elements from second should be inserted. second.

    Returns
    Type Description
    IEnumerable<T>

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

    Type Parameters
    Name Description
    T

    Type of elements in all sequences.

    Remarks

    This operator uses deferred execution and streams its results.

    Examples
    Note

    Backsert has been deprecated in favor of Insert. Please see here for documentation on the equivalent method.

    The following code example demonstrates how to insert one sequence into another, using Backsert.

    var first = Enumerable.Range(1, 5);
    var second = Enumerable.Range(1, 5);
                
    // Insert one sequence into another
    var result = first
        .Backsert(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

    index is negative.

    ArgumentOutOfRangeException

    Thrown lazily if index is greater than the length of first.

    © SuperLinq Authors. All rights reserved.