C#中的LinkedList 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); } //在最后添加一个节点 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