Clear() 메서드를 사용하여 LinkedList를 지웁니다.
먼저 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)...