Table of Contents

Method TryLast

Namespace
Gamelogic.Extensions.Algorithms
Assembly
Gamelogic.Extensions.dll

TryLast<T>(IEnumerable<T>, out T)

Try to get the last element of a sequence, if it exists.

[Version(3, 0, 0)]
public static bool TryLast<T>(this IEnumerable<T> source, out T last)

Parameters

source IEnumerable<T>

The source to get the last element from.

last T

The last element of the source, if it exists.

Returns

bool

true if the source is not empty, false otherwise.

Type Parameters

T

The type of elements in the source.

TryLast<T>(IEnumerable<T>, Func<T, bool>, out T)

Try to get the last element of a sequence that satisfies a predicate, if it exists.

[Version(3, 0, 0)]
public static bool TryLast<T>(this IEnumerable<T> source, Func<T, bool> predicate, out T last)

Parameters

source IEnumerable<T>

The source to get the last element from.

predicate Func<T, bool>

The predicate to test the elements against.

last T

The last element of the source that satisfies the predicate, if it exists.

Returns

bool

true if the source is not empty, false otherwise.

Type Parameters

T

The type of elements in the source.