Clear() विधि का उपयोग करके LinkedList को साफ़ करें।
आइए पहले एक LinkedList सेट करें।
string [] employees = {"Patrick","Robert","John","Jacob", "Jamie"}; LinkedList<string> list = new LinkedList<string>(employees);
अब, हम LinkedList को साफ़ करते हैं।
list.Clear();
आइए देखें पूरा कोड।
उदाहरण
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); } // clearing list list.Clear(); Console.WriteLine("LinkedList after removing the nodes (empty list)..."); foreach (var emp in list) { Console.WriteLine(emp); } } }
आउटपुट
Patrick Robert John Jacob Jamie LinkedList after removing the nodes (empty list)...