सबसे पहले, एक लिंक्डलिस्ट को नोड्स के साथ सेट करें।
string [] students = {"Tim","Jack","Henry","David","Tom"}; LinkedList<string> list = new LinkedList<string>(students);
नोड को पहले स्थान पर जोड़ने के लिए, AddFirst() विधि का उपयोग करें।
list.AddFirst("Amit");
उदाहरण
using System; using System.Collections.Generic; class Demo { static void Main() { string [] students = {"Tim","Jack","Henry","David","Tom"}; LinkedList<string> list = new LinkedList<string>(students); foreach (var stu in list) { Console.WriteLine(stu); } // adding a node Console.WriteLine("LinkedList after adding a node at the first position..."); list.AddFirst("Amit"); foreach (var stu in list) { Console.WriteLine(stu); } } }
आउटपुट
Tim Jack Henry David Tom LinkedList after adding a node at the first position... Amit Tim Jack Henry David Tom