ListExtensions.Last<T>

Extension Method in ListExtensions

Declaration

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

Description

Returns the last item in the list.

Type Parameters

TThe type of the list.

Parameters

listThe list to get the item from.

Returns

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

Overload

Declaration

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

Description

Returns the last 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 last item in the list that satisfies the predicate, or default(T) if no item satisfies the predicate.