Tutorialspoint

C# Clear a Linked List

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);  
      }    
   }
}

Advertisements
Loading...