Thursday 25 July 2013

Difference between Arraylist and Generic List


Difference between Arraylist and Generic List

Arraylist
 
Arraylist accept values as object

So We can give any type of data in to that.

Here in this eg: an arraylist object accepting 

values like String,int,decimal, char and a custom object

ArrayList arr = new ArrayList();

arr.Add("Sabu");

arr.Add(234);

arr.Add(45.236);

arr.Add(emp);

arr.Add('s');

This process is known as boxing
 
Geniric
 
Main advantage of Generic List is we can specify the type of data 
List<int> intLst = new List<int>();

intLst.Add(12);
 
Here List accepting values as int only
 
List<Employee> empLst = new List<Employee>();


empLst.Add(new Employee("1", "Sabu"));
Here List accepting Employee Objects only
 
 If constructor is private then we can not create the object and inherit of that
class.
   
 -> Sealed can not be used for virtual, Abstract and static classes.
Non - Generic collection class - which collection can hold the different type of data.
Generic collection class - which collection can hold the same type of data.

No comments:

Post a Comment