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);
}
// 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...
广告
数据结构
数据网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP