Table of Contents

Marble diagram

If the sequence has no elements, Last will terminate with an error.

Examples

Use Last to retrieve the last element of a sequence.

Last Example

Use TakeLast to retrieve one or more elements from the end of the sequence.

Warning

There is a subtle but important difference between the Last operator and TakeLast(1). TakeLast(1) will complete successfully when the source sequence has no elements.

Use LastOrDefault to retrieve the last element or return a default element if the sequence is empty.