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
2010-02-22 08:38:30
Another point worth mentioning is that a generic list eliminates boxing for value types.
Joe
2010-02-22 08:43:26
@Joe: Yeah, I mentioned that in my third sentence.
Mehrdad Afshari
2010-02-22 08:45:04