C# | Array.FindLast() Method Last Updated : 17 Dec, 2021 Comments Improve Suggest changes Like Article Like Report This method is used to search for an element that matches the conditions defined by the specified predicate and returns the last occurrence within the entire Array. Syntax: public static T FindLast<T> (T[] array, Predicate<T> match); Parameters: array: It is the one-dimensional, zero-based array to search. match: It is the predicate that defines the conditions of the element to search for. Return Value: This method returns the last element that matches the conditions defined by the specified predicate if it is found otherwise returns the default value for type T. Exception: This method throws ArgumentNullException if the array is null or match is null. Below programs illustrate the use of Array.FindLast(T[], Predicate) Method: Example 1: CSHARP // C# program to demonstrate // Array.FindLast(T[], Predicate<T>) // Method using System; using System.Collections.Generic; public class GFG { // Main Method public static void Main() { try { // Creating and initializing // new the String String[] myArr = {"Sun", "Son", "Tue", "Thu"}; // Display the values of the myArr. Console.WriteLine("Initial Array:"); // calling the PrintIndexAndValues() // method to print PrintIndexAndValues(myArr); // getting a last element with required // condition using method FindLast() string value = Array.FindLast(myArr, element => element.StartsWith("S", StringComparison.Ordinal)); // Display the value of // the found element. Console.Write("Last occurrence: "); // printing the string // following the condition Console.Write("{0}", value); } catch (ArgumentNullException e) { Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } } // Defining the method // PrintIndexAndValues public static void PrintIndexAndValues(String[] myArr) { for (int i = 0; i < myArr.Length; i++) { Console.WriteLine("{0}", myArr[i]); } Console.WriteLine(); } } Output: Initial Array: Sun Son Tue Thu Last occurrence: Son Example 2: CSHARP // C# program to demonstrate // Array.FindLast(T[], Predicate<T>) // Method using System; using System.Collections.Generic; public class GFG { // Main Method public static void Main() { try { // Creating and initializing // new Array String with null String[] myArr = null; // getting a last element with required // condition using method FindLast() string value = Array.FindLast(myArr, element => element.StartsWith("S", StringComparison.Ordinal)); // Display the value of // the found element. Console.Write("Last occurrence: "); // printing the string // following the condition Console.Write("{0}", value); } catch (ArgumentNullException e) { Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } } // Defining the method // PrintIndexAndValues public static void PrintIndexAndValues(String[] myArr) { for (int i = 0; i < myArr.Length; i++) { Console.WriteLine("{0}", myArr[i]); } Console.WriteLine(); } } Output: Exception Thrown: System.ArgumentNullException Reference: https://docs.microsoft.com/en-us/dotnet/api/system.array.findlast?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Array.FindLast() Method rohitprasad3 Follow Improve Article Tags : C# CSharp-method CSharp-Arrays Similar Reads Array.LastIndexOf Method in C# | Set - 1 Array.LastIndexOf method is used to find the last matching element in a one-dimensional array. It starts the search from the last element of an array. It returns the index of the element that contains the specified value. There are 6 methods in the overload list of this method as follows: LastIndexO 8 min read Array.LastIndexOf Method in C# | Set â 2 Array.LastIndexOf method is used to find the index of the last occurrence of a value in a one-dimensional Array or in a portion of the Array. It starts the search from the last element of an array. It returns the index of the element that contains the specified value. There are 6 methods in the over 4 min read C# | Array.LastIndexOf<T>(T[], T) Method Array.LastIndexOf<T>(T[], T) Method is used to search for the specified object. It returns the index of the last occurrence within the entire Array. Syntax: public static int LastIndexOf<T>(T[] array, T value); Parameters: array: It is a one-dimensional, zero-indexed array to search. val 2 min read C# | Finding the index of last element in the array GetUpperBound() Method is used to find the index of the last element of the specified dimension in the array. Syntax: public int GetUpperBound (int dimension); Here, dimension is a zero-based dimension of the array whose upper bound needs to be determined. Return Value:The return type of this method 2 min read C# | Array.BinarySearch(Array, Object, IComparer) Method This method searches for a value in a one-dimensional sorted array using a specified IComparer interface. Syntax: public static int BinarySearch(Array arr, Object val, IComparer comparer) Parameters: arr : The one-dimensional sorted array in which the search will happen. val : The object value which 4 min read C# | Array.BinarySearch(Array, Int32, Int32, Object, IComparer) Method This method searches for an element which is in a one-dimensional sorted array within a range of elements using a specified IComparer interface. Syntax: public static int BinarySearch(Array arr, int index, int length, Object value, IComparer comparer) Parameters: arr : The sorted one-dimensional Arr 4 min read C# | Find the last node in LinkedList<T> containing the specified value LinkedList<T>.FindLast(T) method is used to find the last node that contains the specified value. Syntax: public System.Collections.Generic.LinkedListNode<T> FindLast (T value); Here, value is the value to locate in the LinkedList. Return Value: This method returns the last LinkedListNod 2 min read C++ Program for Last duplicate element in a sorted array We have a sorted array with duplicate elements and we have to find the index of last duplicate element and print index of it and also print the duplicate element. If no such element found print a message. Examples: Input : arr[] = {1, 5, 5, 6, 6, 7} Output : Last index: 4 Last duplicate item: 6 Inpu 2 min read JavaScript Array findLast() Method The JavaScript findLast() method is used to retrieve the last element in an array that meets a specified condition.Example 1: This example shows how findLast() can be used to find the last even number in an array.JavaScriptconst a = [1, 3, 5, 7, 6, 8]; const b = a.findLast(num => num % 2 === 0); 2 min read Ints lastIndexOf() function | Guava | Java Guava's Ints.lastIndexOf() returns the index of the last appearance of the value target in array. Syntax: public static int lastIndexOf(int[] array, int target) Parameters: array: An array of int values, possibly empty. target: A primitive int value. Return Value: The Ints.indexOf() method returns t 2 min read Like