Declare a LinkedList using the LinkedList collection in X# −
var a = new LinkedList < string > ();
Now add elements to the LinkedList −
a.AddLast("Tim");
a.AddLast("Tom");Let us see how to perform traversal in a LinkedList −
Example
using System;
using System.Collections.Generic;
public class Demo {
public static void Main(string[] args) {
var a = new LinkedList < string > ();
a.AddLast("Tim");
a.AddLast("Tom");
foreach(var res in a) {
Console.WriteLine(res);
}
}
}