Last Updated : 11 Jul, 2025
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,
nodeis the LinkedListNode<
T> to remove from the LinkedList<
T>.
Exceptions: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 8Example 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 ENote:
This method is an O(1) operation.
Reference: https://learn.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__RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4