C#中的LinkedList Clear()方法
使用该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...