List<T>.FindLast(Predicate<T>) Method is used to search for an element which matches the conditions defined by the specified predicate and it returns the last occurrence of that element within the entire List<T>.
Properties of List:
- It is different from the arrays. A list can be resized dynamically but arrays cannot.
- List class can accept null as a valid value for reference types and it also allows duplicate elements.
- If the Count becomes equals to Capacity then the capacity of the List increases automatically by reallocating the internal array. The existing elements will be copied to the new array before the addition of the new element.
public T FindLast (Predicate<T> match);
match: It is the Predicate<T> delegate which defines the conditions of the element which is to be searched.
Return Value: If the element found then this method will return the last element that matches the conditions defined by the specified predicate otherwise it returns the default value for type T.
Exception: This method will give ArgumentNullException if the match is null.
Below programs illustrate the use of List<T>.FindLast(Predicate<T>) Method:
Elements Present in List: At Position 0: 4 At Position 1: 2 At Position 2: 7 At Position 3: 2 At Position 4: 6 At Position 5: 4 At Position 6: 3 Index of Last element that fullfill the conditions: 5 Element is: 4
Elements Present in List: At Position 0: 17 At Position 1: 19 At Position 2: 21 At Position 3: 9 At Position 4: 75 At Position 5: 19 At Position 6: 73 Index of Last element that fullfill the conditions: -1 Element is: 0
- C# | How to get all elements of a List that match the conditions specified by the predicate
- C# | How to check whether a List contains the elements that match the specified conditions
- C# | Check if an array contain the elements that match the specified conditions
- C# | First occurrence in the List that matches the specified conditions
- C# | Remove all elements of a List that match the conditions defined by the predicate
- C# | Removing first occurrence of specified value from LinkedList<T>
- C# | Get or set the element at specified index in Collection<T>
- C# | Get or set the element at the specified index in ArrayList
- C# | Find the last node in LinkedList<T> containing the specified value
- C# | Check if every List element matches the predicate conditions
- C# | Removing the specified element from the List
- C# | Gets or Sets the element at the specified index in the List
- C# | How to remove the element from the specified index of the List
- C# | How to perform a specified action on each element of the List
- C# | How to check whether a List contains a specified element
- C# | Get or Set at specified index in StringCollection
- C# | Get or Set the value associated with specified key in Hashtable
- C# | Get or set the value associated with the specified key in StringDictionary
- C# | Get or set the value associated with specified key in ListDictionary
- C# | Get or set the value associated with specified key in SortedList
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai