MoreEnumerableInsertT Method

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

Definition

Namespace: MoreLinq
Assembly: MoreLinq (in MoreLinq.dll) Version: 3.4.0+b99a6a8cc504caf2d48372fe54a2f8116c59cd0c
C#
public static IEnumerable<T> Insert<T>(
	this IEnumerable<T> first,
	IEnumerable<T> second,
	int index
)

Parameters

first  IEnumerableT
The source sequence.
second  IEnumerableT
The sequence that will be inserted.
index  Int32
The zero-based index at which to insert elements from second.

Type Parameters

T
Type of the elements of the source sequence.

Return Value

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

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).

Exceptions

ArgumentNullExceptionfirst is null.
ArgumentNullExceptionsecond 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.

See Also