Method TryFirst
- Namespace
- Gamelogic.Extensions.Algorithms
- Assembly
- Gamelogic.Extensions.dll
TryFirst<T>(IEnumerable<T>, out T)
Try to get the first element of a sequence, if it exists.
[Version(3, 0, 0)]
public static bool TryFirst<T>(this IEnumerable<T> source, out T first)
Parameters
source
IEnumerable<T>The source to get the first element from.
first
TThe first element of the source, if it exists.
Returns
Type Parameters
T
The type of elements in the source.
TryFirst<T>(IEnumerable<T>, Func<T, bool>, out T)
Try to get the first element of a sequence that satisfies a predicate, if it exists.
[Version(3, 0, 0)]
public static bool TryFirst<T>(this IEnumerable<T> source, Func<T, bool> predicate, out T first)
Parameters
source
IEnumerable<T>The source to get the first element from.
predicate
Func<T, bool>The predicate to test the elements against.
first
TThe first element of the source that satisfies the predicate, if it exists.
Returns
Type Parameters
T
The type of elements in the source.