获取C#中LinkedList的第一个节点
要获取LinkedList的第一个节点,代码如下-
示例
using System;
using System.Collections.Generic;
public class Demo {
public static void Main(){
LinkedList<String> list = new LinkedList<String>();
list.AddLast("A");
list.AddLast("B");
list.AddLast("C");
list.AddLast("D");
list.AddLast("E");
list.AddLast("F");
list.AddLast("G");
list.AddLast("H");
list.AddLast("I");
list.AddLast("J");
Console.WriteLine("Count of nodes = " + list.Count);
Console.WriteLine("First Node = "+list.First.Value);
list.Clear();
Console.WriteLine("Count of nodes (updated) = " + list.Count);
}
}输出结果
这将产生以下输出-
Count of nodes = 10 First Node = A Count of nodes (updated) = 0
示例
让我们看另一个例子-
using System;
using System.Collections.Generic;
public class Demo {
public static void Main(){
LinkedList<int> list = new LinkedList<int>();
list.AddLast(100);
list.AddLast(200);
list.AddLast(300);
list.AddLast(400);
list.AddLast(500);
list.AddLast(600);
list.AddLast(700);
list.AddLast(800);
list.AddLast(900);
list.AddLast(1000);
Console.WriteLine("Count of nodes = " + list.Count);
Console.WriteLine("First Node = "+list.First.Value);
Console.WriteLine("Last Node = "+list.Last.Value);
list.Clear();
Console.WriteLine("Count of nodes (updated) = " + list.Count);
}
}输出结果
这将产生以下输出-
Count of nodes = 10 First Node = 100 Last Node = 1000 Count of nodes (updated) = 0
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语