LinkedList 在 C# 中的 AddLast 方法
声明一个字符串数组。
string [] students = {"Jenifer","Angelina","Vera"};
将其添加到 LinkedList 中。
string [] students = {"Jenifer","Angelina","Vera"};
现在,使用 AddLast() 方法在末尾添加一个节点。
list.AddLast("Anne");
范例
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
广告