C# | Removing the specified node from the LinkedList<T> Last Updated : 01 Feb, 2019 Comments Improve Suggest changes Like Article Like Report Remove(LinkedListNode<T>) method is used to remove the specified node from the LinkedList<T>. Syntax: public void Remove (System.Collections.Generic.LinkedListNode<T> node); Here, node is the LinkedListNode<T> to remove from the LinkedList<T>. Exceptions: ArgumentNullException : If the node is null. InvalidOperationException : If the node is not in the current LinkedList<T>. Below given are some examples to understand the implementation in a better way: Example 1: CSHARP // C# code to remove the specified // node from the LinkedList 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(2); myList.AddLast(4); myList.AddLast(6); myList.AddLast(8); // To get the count of nodes in LinkedList // before removing all the nodes Console.WriteLine("Total nodes in myList are : " + myList.Count); // Displaying the nodes in LinkedList foreach(int i in myList) { Console.WriteLine(i); } // Removing the first node from the LinkedList myList.Remove(myList.First); // To get the count of nodes in LinkedList // after removing all the nodes Console.WriteLine("Total nodes in myList are : " + myList.Count); // Displaying the nodes in LinkedList foreach(int i in myList) { Console.WriteLine(i); } } } Output: Total nodes in myList are : 4 2 4 6 8 Total nodes in myList are : 3 4 6 8 Example 2: CSHARP // C# code to remove the specified // node from the LinkedList 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"); // To get the count of nodes in LinkedList // before removing all the nodes Console.WriteLine("Total nodes in myList are : " + myList.Count); // Displaying the nodes in LinkedList foreach(string str in myList) { Console.WriteLine(str); } // Removing the specified node from the LinkedList myList.Remove("D"); // To get the count of nodes in LinkedList // after removing all the nodes Console.WriteLine("Total nodes in myList are : " + myList.Count); // Displaying the nodes in LinkedList foreach(string str in myList) { Console.WriteLine(str); } } } Output: Total nodes in myList are : 5 A B C D E Total nodes in myList are : 4 A B C E Note: This method is an O(1) operation. Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.linkedlist-1.remove?view=netframework-4.7.2#System_Collections_Generic_LinkedList_1_Remove_System_Collections_Generic_LinkedListNode__0__ Comment More infoAdvertise with us Next Article C# | Removing the specified node from the LinkedList<T> S Sahil_Bansall Follow Improve Article Tags : C# CSharp-Generic-Namespace CSharp-LinkedList CSharp-LinkedList-Methods Similar Reads 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# | Removing all nodes from LinkedList<T> LinkedList<T>.Clear method is used to remove the all nodes from the LinkedList<T>. Syntax: public void Clear (); Below given are some examples to understand the implementation in a better way: Example 1: CSHARP // C# code to remove all // nodes from LinkedList using System; using System. 2 min read C# | Removing the node at the start of the LinkedList<T> LinkedList<T>.RemoveFirst method is used to remove the node at the start of the LinkedList<T>. Syntax: public void RemoveFirst (); Exception: The method throws InvalidOperationException if the LinkedList<T> is empty. Below given are some examples to understand the implementation in 2 min read C# | Removing the specified element from the List List.Remove(T) Method is used to remove the first occurrence of a specific object from the List. 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 elem 2 min read C# | How to remove the element from the specified index of the List List<T>.RemoveAt (Int32) Method is used to remove the element at the specified index of the 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 allow 3 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# LinkedList Class LinkedList<T> class in C# is the part of the removal namespace. This generic type allows fast inserting and removal of elements. It implements a classic linked list. Each object is separately allocated. In the LinkedList, certain operations do not require the whole collection to be copied. But 5 min read C# Program For Removing Duplicates From A Sorted Linked List Write a function that takes a list sorted in non-decreasing order and deletes any duplicate nodes from the list. The list should only be traversed once. For example if the linked list is 11->11->11->21->43->43->60 then removeDuplicates() should convert the list to 11->21->43- 8 min read C# Program For Removing Duplicates From An Unsorted Linked List Write a removeDuplicates() function that takes a list and deletes any duplicate nodes from the list. The list is not sorted. For example if the linked list is 12->11->12->21->41->43->21 then removeDuplicates() should convert the list to 12->11->21->41->43. Recommended: 4 min read Like