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
廣告