tags:

views:

253

answers:

1

what is the difference between arraylist and List<> in c#? is it only that List<> have a type while ArrayList don't?

+16  A: 

Yes, pretty much. List<T> is a generic class. It supports storing values of a specific type without boxing to and unboxing from object. ArrayList simply stores object references. As a generic collection, it implements the generic IEnumerable<T> interface and can be used easily in LINQ (without requiring any Cast or OfType call).

ArrayList belongs to the days that C# didn't have generics. It's deprecated in favor of List<T>. You shouldn't use ArrayList in new code that targets .NET >= 2.0 unless you have to interface with an old API that uses it.

Mehrdad Afshari
Another point worth mentioning is that a generic list eliminates boxing for value types.
Joe
@Joe: Yeah, I mentioned that in my third sentence.
Mehrdad Afshari