C# 中的 LinkedList RemoveFirst() 方法
假设我们的 LinkedList 如下,其中整数为节点。
int [] num = {29, 40, 67, 89, 198, 234};
LinkedList<int> myList = new LinkedList<int>(num);现在,如果你想从列表中删除第一个元素,那么使用 RemoveFirst() 方法即可。
myList.RemoveFirst();
示例
using System;
using System.Collections.Generic;
class Demo {
static void Main() {
int [] num = {29, 40, 67, 89, 198, 234};
LinkedList<int> myList = new LinkedList<int>(num);
foreach (var n in myList) {
Console.WriteLine(n);
}
// removing first node
myList.RemoveFirst();
Console.WriteLine("LinkedList after removing the first node...");
foreach (var n in myList) {
Console.WriteLine(n);
}
}
}输出
29 40 67 89 198 234 LinkedList after removing the first node... 40 67 89 198 234
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP