清除 C# 中的链表
使用 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)...
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP