var list = new ArrayList();
list.Add(44); //boxing, convert a value type to a reference type.
int i1 = (int)list[0]; //unboxing, convert a reference type to a value type.
foreach(int i2 in list)
{
Console.WriteLine(i2);
}
Note: Boxing and unboxing are easy to use but have a big performance impact, especially when iterating through many times.
Instead of using ArrayList, use the List
var list = new List
list.Add(44);
int i1 = list[0];
foreach(int i2 in list)
{
Console.WriteLine(i2);
}
Comments are Welcome.
Jignesh TrivediPosted Jun 3, 2013, 3:52 AM
hi,
yes there is an performance hit in boxing and unboxing.
Please refer
http://msdn.microsoft.com/en-us/library/ms173196(v=vs.80).aspx