ล้าง LinkedList โดยใช้วิธี Clear()
ให้เราตั้งค่า LinkedList ก่อน
พนักงานstring [] employees = {"Patrick","Robert","John","Jacob", "Jamie"};
LinkedList<string> list = new LinkedList<string>(employees); ตอนนี้ ให้เราเคลียร์ LinkedList
list.Clear();
ให้เราดูรหัสที่สมบูรณ์
ตัวอย่าง
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);
}
// clearing list
list.Clear();
Console.WriteLine("LinkedList after removing the nodes (empty list)...");
foreach (var emp in list) {
Console.WriteLine(emp);
}
}
} ผลลัพธ์
Patrick Robert John Jacob Jamie LinkedList after removing the nodes (empty list)...