Legend

Class
Struct
Enum
Interface
Delegate
Constructor
Method
Property
Event
Field

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

Declaration

public static T FirstOrDefault<T>(
    this IEnumerable<T> source,
    Func<T, bool> predicate,
    T default
)

Summary

Returns the first element of a sequence, or a default value if the sequence contains no elements.

Generic type parameters

T 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 A function to test each element for a condition.
Tdefault The default value to return if the sequence contains no elements.

Returns

default if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate.