สมมติว่าต่อไปนี้คือ LinkedList ของเราที่มีโหนดจำนวนเต็ม
int [] num = {29, 40, 67, 89, 198, 234};
LinkedList<int> myList = new LinkedList<int>(num); ตอนนี้ ถ้าคุณต้องการลบองค์ประกอบแรกออกจากรายการ ให้ใช้เมธอด RemoveFirst()
myList.RemoveFirst();
ตัวอย่าง
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);
}
}
} ผลลัพธ์
29 40 67 89 198 234 LinkedList after removing the first node... 40 67 89 198 234