Wednesday, 22 February 2012

ArrayList Argument Is an Array?

Yes, ArrayList Accepts Array as a Argument.the resoan behind this is Array implements ICollection interface
and ICollection is Arguement to ArrayList.

Ex:1
  System.Collection;       
               int[] intarr={10,20,30,40,50};
               Console.WriteLine(intarr[4]);
               Console.WriteLine(intarr.Length);

               ArrayList arrlist = new ArrayList(intarr);
               Console.WriteLine(arrlist[4]);
               Console.WriteLine(arrlist.Count);
              // integer array is argugment to ArrayList why because ArrayList Implements ICollection.                        
               Console.ReadKey();
         
Ex :2
String Array is Arguement to ArrayList


           string[] strarr = { "kasi", "babu", "ravi", "kumar" };
            ArrayList strlist = new ArrayList(strarr);
            Console.WriteLine(strlist[3]);


Note: ArrayList accepts any Array it can be string,bool,decimal......ect why because Array implements ICollection.

No comments:

Post a Comment