ใช้วิธี Clear() เพื่อล้าง LinkedList การดำเนินการนี้จะลบโหนดทั้งหมดออกจาก LinkedList
สมมติว่าต่อไปนี้คือ LinkedList ของเรา -
int [] num = {30, 65, 80, 95, 110, 135};
LinkedList<int> list = new LinkedList<int>(num); เพื่อล้าง LinkedList
list.Clear();
ตัวอย่าง
using System;
using System.Collections.Generic;
class Demo {
static void Main() {
int [] num = {30, 65, 80, 95, 110, 135};
LinkedList<int> list = new LinkedList<int>(num);
foreach (var n in list) {
Console.WriteLine(n);
}
// clear
list.Clear();
Console.WriteLine("No node in the LinkedList now...");
foreach (var n in list) {
Console.WriteLine(n);
}
}
} ผลลัพธ์
30 65 80 95 110 135 No node in the LinkedList now...