ListExtensions.First<T>

Extension Method in ListExtensions

Declaration

public static T First<T>(this List<T> list)

Description

Returns the first item in the list.

Type Parameters

TThe type of the list.

Parameters

listThe list to get the item from.

Returns

TThe first item in the list, or default(T) if the list is empty.

Overload

Declaration

public static T First<T>(this List<T> list, Predicate<T> predicate)

Description

Returns the first item in the list that satisfies a predicate.

Type Parameters

TThe type of the list.

Parameters

listThe list to get the item from.
predicateThe predicate to use.

Returns

TThe first item in the list that satisfies the predicate, or default(T) if no item satisfies the predicate.