Legend

Class
Struct
Enum
Interface
Delegate
Constructor
Method
Property
Event
Field

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

Declaration

public static T? FirstOrNull<T>(
    this IEnumerable<T> source
)

Summary

Returns the first element of a sequence, 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.

Returns

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