TryFind
Returns the first element for which the given predicate function returns true.
Returns an Option<T> that IsNone if no such element exists.
Parameters
Returns
Func<T, bool> predicate
IEnumerable<T> source
Option<T>
Usage
Getting an element
//IEnumerable<int> source = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
Option<int> result = source.TryFind(value => value == 5);
//result.IsSome = true
//result.Some = 5When there is no element that satisfies the condition
//IEnumerable<int> source = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
Option<int> result = source.TryFind(value => value == 15);
//result.IsSome = false
//result.IsNone = trueLast updated
Was this helpful?