To remove a node at the beginning of a LinkedList, use the RemoveFirst() method.
string [] employees = {"Peter","Robert","John","Jacob"};
LinkedList<string> list = new LinkedList<string>(employees);Now, to remove the first element, use the RemoveFirst() method.
list.RemoveFirst();
Let us see the complete example.
Example
using System;
using System.Collections.Generic;
class Demo {
static void Main() {
string [] employees = {"Peter","Robert","John","Jacob"};
LinkedList<string> list = new LinkedList<string>(employees);
foreach (var emp in list) {
Console.WriteLine(emp);
}
// removing first node
list.RemoveFirst();
Console.WriteLine("LinkedList after removing first node...");
foreach (var emp in list) {
Console.WriteLine(emp);
}
}
}Output
Peter Robert John Jacob LinkedList after removing first node... Robert John Jacob