Use foreach loop to display the ArrayList : ArrayList Display : Data Structure C# Examples


C# Examples » Data Structure » ArrayList Display »

 

Use foreach loop to display the ArrayList









    
using  System;  
using  System.Collections;  
  
class  MainClass  {  
    public  static  void  Main()  {  
        ArrayList  al  =  new  ArrayList();  
          
        Console.WriteLine("Adding  6  elements");  
        //  Add  elements  to  the  array  list  
        al.Add('C');  
        al.Add('A');  
        al.Add('E');  
        al.Add('B');  
        al.Add('D');  
        al.Add('F');  
  
        //  Use  foreach  loop  to  display  the  list.  
        Console.Write("Contents:  ");  
        foreach(char  c  in  al)  
            Console.Write(c  +  "  ");  
        Console.WriteLine("\n");  
  
    }
}
    
   
  
   



Output

Adding 6 elements
Contents: C A E B D F


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Structure
» ArrayList Display