HeadAndTailEnd

Returns a typle with the first and the last element of the collection.

Parameters

Returns

IEnumerable<T> source

(T Head, T TailEnd)

Exceptions

Type

When

InvalidOperationException

It is an empty collection.

Usage

Getting the first and the last elements

//IEnumerable<int> source = { 5, 8, 9, 10 }
int result = source.HeadAndTailEnd();

//result = (5, 10)

Getting the first and the last elements in a single element collection

//IEnumerable<int> source = { 42 }
int result = source.HeadAndTailEnd();

//result = (42, 42)

Last updated