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...