Giả sử sau đây là Danh sách liên kết của chúng tôi với các nút số nguyên.
int [] num = {29, 40, 67, 89, 198, 234};
LinkedList<int> myList = new LinkedList<int>(num); Bây giờ, nếu bạn muốn xóa phần tử đầu tiên khỏi danh sách, hãy sử dụng phương thức RemoveFirst ().
myList.RemoveFirst();
Ví dụ
using System;
using System.Collections.Generic;
class Demo {
static void Main() {
int [] num = {29, 40, 67, 89, 198, 234};
LinkedList<int> myList = new LinkedList<int>(num);
foreach (var n in myList) {
Console.WriteLine(n);
}
// removing first node
myList.RemoveFirst();
Console.WriteLine("LinkedList after removing the first node...");
foreach (var n in myList) {
Console.WriteLine(n);
}
}
} Đầu ra
29 40 67 89 198 234 LinkedList after removing the first node... 40 67 89 198 234