C# | Find the last node in LinkedList<T> containing the specified value Last Updated : 01 Feb, 2019 Comments Improve Suggest changes Like Article Like Report 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 LinkedListNode<T> that contains the specified value, if found, otherwise, null. Below given are some examples to understand the implementation in a better way: Example 1: CSHARP // C# code to find the last node // that contains the specified value using System; using System.Collections; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a LinkedList of Strings LinkedList<String> myList = new LinkedList<String>(); // Adding nodes in LinkedList myList.AddLast("A"); myList.AddLast("B"); myList.AddLast("C"); myList.AddLast("D"); myList.AddLast("E"); // Finding the last node that // contains the specified value LinkedListNode<String> temp = myList.Find("D"); Console.WriteLine(temp.Value); } } Output: D Example 2: CSHARP // C# code to find the last node // that contains the specified value using System; using System.Collections; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a LinkedList of Integers LinkedList<int> myList = new LinkedList<int>(); // Adding nodes in LinkedList myList.AddLast(5); myList.AddLast(7); myList.AddLast(9); myList.AddLast(11); myList.AddLast(12); // Finding the last node that // contains the specified value LinkedListNode<int> temp = myList.Find(2); Console.WriteLine(temp.Value); } } Runtime Error: Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object Note: The LinkedList is searched backward starting at Last and ending at First. This method performs a linear search. Therefore, this method is an O(n) operation, where n is Count. Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.linkedlist-1.findlast?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Find the last node in LinkedList<T> containing the specified value S Sahil_Bansall Follow Improve Article Tags : C# CSharp-Generic-Namespace CSharp-LinkedList CSharp-LinkedList-Methods Similar Reads C# | Find the first node in LinkedList<T> containing the specified value LinkedList<T>.Find(T) method is used to find the first node that contains the specified value. Syntax: public System.Collections.Generic.LinkedListNode<T> Find (T value); Here, value is the value to locate in the LinkedList. Return Value: This method returns the first LinkedListNode<T 2 min read C# | Get the last node of the LinkedList<T> LinkedList<T>.Last property is used to get the last node of the LinkedList<T>. Syntax: public System.Collections.Generic.LinkedListNode Last { get; } Return Value: The last LinkedListNode<T> of the LinkedList<T>. Below given are some examples to understand the implementation 2 min read C# | Get the number of nodes contained in LinkedList<T> LinkedList<T>.Count property is used to get the number of nodes actually contained in the LinkedList<T>. Syntax: public int Count { get; } Return Value: The number of nodes actually contained in the LinkedList. Note: Retrieving the value of this property is an O(1) operation. Below given 2 min read C# | Get the first node of the LinkedList<T> LinkedList<T>.First property is used to get the first node of the LinkedList<T>. Syntax: public System.Collections.Generic.LinkedListNode First { get; } Return Value: The first LinkedListNode<T> of the LinkedList<T>. Below given are some examples to understand the implementat 2 min read C# | Adding new node or value at the end of LinkedList<T> LinkedList<T>.AddLast Method is used to add a new node or value at the end of the LinkedList<T>. There are 2 methods in the overload list of this method as follows: AddLast(LinkedList<T>) AddLast(T) AddLast(LinkedListNode<T>) This method is used to add the specified new node 3 min read C# | Adding new node or value at the start of LinkedList<T> LinkedList<T>.AddFirst Method is used to add a new node or value at the starting of the LinkedList<T>. There are 2 methods in the overload list of this method as follows: AddFirst(LinkedList<T>) AddFirst(T) AddFirst(LinkedListNode<T>) This method is used to add the specified 3 min read C# | Removing the node at the end of LinkedList<T> LinkedList<T>.RemoveLast method is used to remove the node at the end of the LinkedList<T>. Syntax: public void RemoveLast (); Exception: The method throws InvalidOperationException if the LinkedList<T> is empty. Below given are some examples to understand the implementation in a b 2 min read C# | Check if a value is in LinkedList<T> LinkedList<T>.Contains(T) method is used to check whether a value is in the LinkedList<T> or not. Syntax: public bool Contains (T value); Here, value is the value to locate in the LinkedList<T>. The value can be null for reference types. Return Value: This method returns True if va 2 min read List FindLastIndex() Method in C# | Set -2 This method is used to search for an element which matches the conditions defined by a specified predicate and returns the zero-based index of the last occurrence within the List<T> or a portion of it. There are 3 methods in the overload list of this method: FindLastIndex(Predicate<T>) M 5 min read List FindLastIndex() Method in C# | Set -1 This method is used to search for an element which matches the conditions defined by a specified predicate and returns the zero-based index of the last occurrence within the List<T> or a portion of it. There are 3 methods in the overload list of this method: FindLastIndex(Predicate<T>) M 3 min read Like