ใช้เมธอด 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);
}
// ล้าง
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...