TakeLast - Kalkwst/Risotto GitHub Wiki

Definition

Returns the specified number of contiguous elements from the end of a sequence.

In this page

Overloads

Overload Description
TakeLast(int n) Returns the specified number of contiguous elements from the end of a sequence.

TakeLast(int n)

Returns the specified number of contiguous elements from the end of a sequence.

Type Parameters

T
The type of the elements of source.

Parameters

source IEnumerable <TSource>
A sequence to get the n last elements of.

n Int32
The number of elements to get from the end of the sequence.

Returns

IEnumerable <TSource>
The n last elements of the sequence.

Exceptions

ArgumentNullException

source is null

ArgumentOutOfRangeException

n is negative.

Example

The following code example demonstrates how to use public static IEnumerable TakeLast(int n) to get the last n elements of a sequence.

var sequence = new[] { 12, 34, 56, 78, 910, 1112 };
var skimmed = sequence.TakeLast(3);
//=> [ 78, 910, 1112 ]
⚠️ **GitHub.com Fallback** ⚠️