protected void Button1_Click(object sender, EventArgs e)
{
ArrayList arrLst = new ArrayList();
// Add UserInfo object into array list
UserInfo u1 = new UserInfo();
u1.FirstName = "Satalaj";
u1.LastName = "More";
arrLst.Add(u1);
UserInfo u2 = new UserInfo();
u2.FirstName = "Mike";
u2.LastName = "Marco";
arrLst.Add(u2);
//Add ProductInfo object into array list
ProductInfo p1 = new ProductInfo();
p1.ProductName = "Samsung";
arrLst.Add(p1);
ProductInfo p2 = new ProductInfo();
p2.ProductName = "Nokia";
arrLst.Add(p2);
foreach(object o in arrLst)
{
try
{
// lets iterate objects in arraylist and get their type / member info
// I have applied try catch block here bcoz you can see
// arrays are not type safe
System.Type type = o.GetType();string str = type.Name ;
Response.Write(str);
Response.Write("<Br />");
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
}
}