निम्नलिखित हमारी लिंक्डलिस्ट है।
string [] employees = {"Patrick","Robert","John","Jacob", "Jamie"}; LinkedList<string> list = new LinkedList<string>(employees);
अब, मान लें कि आपको अंतिम नोड यानी "जेमी" को हटाने की आवश्यकता है। उसके लिए, RemoveLast() विधि का उपयोग करें।
list.RemoveLast();
उदाहरण
using System; using System.Collections.Generic; class Demo { static void Main() { string [] employees = {"Patrick","Robert","John","Jacob", "Jamie"}; LinkedList<string> list = new LinkedList<string>(employees); foreach (var emp in list) { Console.WriteLine(emp); } // removing last node list.RemoveLast(); Console.WriteLine("LinkedList after removing last node..."); foreach (var emp in list) { Console.WriteLine(emp); } } }
आउटपुट
Patrick Robert John Jacob Jamie LinkedList after removing last node... Patrick Robert John Jacob