Legend

Class
Struct
Enum
Interface
Delegate
Constructor
Method
Property
Event
Field

Extension method: T? FirstOrNull<T>(this IEnumerable<T>, Func<T, bool>)

Declaration

public static T? FirstOrNull<T>(
    this IEnumerable<T> source,
    Func<T, bool> predicate
)

Summary

Returns the first element of a sequence that satisfies a given predicate, or null if the sequence contains no elements.

Generic type parameters

T
  • Must derive from: System.ValueType.
  • Must have a default constructor.
  • Must be a non-nullable value type.
The type of the elements of source.

Parameters

this IEnumerable<T>source The IEnumerable<T> to return the first element of.
Func<T, bool>predicate Only consider elements that satisfy this predicate.

Returns

null if source is empty; otherwise, the first element in source.