Arraylist and Genric arraylist example in c#



name space :
using System.Collections;

Array list (example program )

1)  arraylist accept any kind of data type


 ArrayList al = new ArrayList();

al.Add("aa");

al.Add("bb");

al.Add(1);

for (int i = 0; i < 3; i++)

{

Label label = new Label();

label.Text = al[i].ToString();

form1.Controls.Add(label);

}


.........................................................................................................

Generic list (example)
we can create using generic perticular data type only

name space :
using System.Collections.Generic;

List lg = new List();

lg.Add(2);

lg.Add("dd"); //// ERROR (NOT ACCEPT STRING)



for (int i = 0; i < 2; i++)

{

Label label = new Label();

label.Text = lg[i].ToString();

form1.Controls.Add(label);

}