C# Collections Part 1: Arraylist

Arraylist:


  • Variable length
  • Insert, Update,Delete data anywhere in the list
  • Type independent
Code:

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using System.Collections;  //Use for all non-generic collections.....  
  7.   
  8. namespace arrayList  
  9. {  
  10.     class Program  
  11.     {  
  12.         static void Main(string[] args)  
  13.         {  
  14.             ArrayList arralist = new ArrayList();  
  15.             arralist.Add(101);  
  16.             arralist.Add("Hasan Sujan");  
  17.             arralist.Add("CSE");  
  18.             arralist.Add("01754704559");  
  19.             print(arralist);  
  20.             arralist.Insert(2,21);  
  21.             print(arralist);  
  22.             Console.ReadKey();  
  23.               
  24.               
  25.         }  
  26.         public static void print(ArrayList arralist)  
  27.         {  
  28.             foreach (var i in arralist)  
  29.             {  
  30.                 Console.WriteLine(i);  
  31.             }  
  32.         }  
  33.     }  
  34. }  
Share:

0 Comments:

Post a Comment