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
sourceIEnumerable<T>The source to get the first element from.
firstTThe first element of the source, if it exists.
Returns
Type Parameters
TThe 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
sourceIEnumerable<T>The source to get the first element from.
predicateFunc<T, bool>The predicate to test the elements against.
firstTThe first element of the source that satisfies the predicate, if it exists.
Returns
Type Parameters
TThe type of elements in the source.