LinkedList 在 C# 中的 AddLast 方法


宣告一個字串陣列。

string [] students = {"Jenifer","Angelina","Vera"};

將其新增到 LinkedList 中。

string [] students = {"Jenifer","Angelina","Vera"};

現在,使用 AddLast() 方法在末尾新增一個節點。

list.AddLast("Anne");

範例

 Live Demo

using System;
using System.Collections.Generic;
class Demo {
   static void Main() {
      string [] students = {"Jenifer","Angelina","Vera"};
      LinkedList<string> list = new LinkedList<string>(students);
      foreach (var stu in list) {
         Console.WriteLine(stu);
      }
      // add a node at the end
      Console.WriteLine("Node added at the last...");
      list.AddLast("Anne");
      foreach (var stu in list) {
         Console.WriteLine(stu);
      }
   }
}

輸出

Jenifer
Angelina
Vera
Node added at the last...
Jenifer
Angelina
Vera
Anne

更新時間:23-6 月-2020

瀏覽 332 次

開啟您的 職業 生涯

完成課程,獲得認證

開始
廣告