MoreEnumerableSliceT Method

Extracts a contiguous count of elements from a sequence at a particular zero-based starting index.

Definition

Namespace: MoreLinq
Assembly: MoreLinq (in MoreLinq.dll) Version: 3.4.0+b99a6a8cc504caf2d48372fe54a2f8116c59cd0c
C#
public static IEnumerable<T> Slice<T>(
	this IEnumerable<T> sequence,
	int startIndex,
	int count
)

Parameters

sequence  IEnumerableT
The sequence from which to extract elements.
startIndex  Int32
The zero-based index at which to begin slicing.
count  Int32
The number of items to slice out of the index.

Type Parameters

T
The type of the elements in the source sequence.

Return Value

IEnumerableT
A new sequence containing any elements sliced out from the source sequence.

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

Remarks

If the starting position or count specified result in slice extending past the end of the sequence, it will return all elements up to that point. There is no guarantee that the resulting sequence will contain the number of elements requested - it may have anywhere from 0 to count.

This method is implemented in an optimized manner for any sequence implementing IListT.

The result of SliceT(IEnumerableT, Int32, Int32) is identical to: sequence.Skip(startIndex).Take(count)

See Also