The following is our LinkedList.
string [] employees = {"Patrick","Robert","John","Jacob", "Jamie"};
LinkedList<string> list = new LinkedList<string>(employees);Now, let’s say you need to remove the last node i.e. “Jamie”. For that, use the RemoveLast() method.
list.RemoveLast();
Example
using System;
using System.Collections.Generic;
class Demo {
static void Main() {
string [] employees = {"Patrick","Robert","John","Jacob", "Jamie"};
LinkedList<string> list = new LinkedList<string>(employees);
foreach (var emp in list) {
Console.WriteLine(emp);
}
// removing last node
list.RemoveLast();
Console.WriteLine("LinkedList after removing last node...");
foreach (var emp in list) {
Console.WriteLine(emp);
}
}
}Output
Patrick Robert John Jacob Jamie LinkedList after removing last node... Patrick Robert John Jacob