Sau đây là Danh sách liên kết của chúng tôi.
string [] employees = {"Patrick","Robert","John","Jacob", "Jamie"};
LinkedList<string> list = new LinkedList<string>(employees); Bây giờ, giả sử bạn cần xóa nút cuối cùng, tức là “Jamie”. Để làm điều đó, hãy sử dụng phương thức RemoveLast ().
list.RemoveLast();
Ví dụ
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);
}
}
} Đầu ra
Patrick Robert John Jacob Jamie LinkedList after removing last node... Patrick Robert John Jacob