Alex Rivera | Logout

ArrayList vs List<object>

Asked 2008-12-24T09:30:19.293
54

I saw this reply from Jon on Initialize generic object with unknown type:

If you want a single collection to contain multiple unrelated types of values, however, you will have to use List<object>

I'm not comparing ArrayList vs List<>, but ArrayList vs List<object>, as both will be exposing elements of type object. What would be the benefit of using either one in this case?

EDIT: It's no concern for type safety here, since both class is exposing object as its item. One still needs to cast from object to the desired type. I'm more interested in anything other than type safety.

EDIT: Thanks Marc Gravell and Sean for the answer. Sorry, I can only pick 1 as answer, so I'll up vote both.

Edit
Report

2 Answers

11

In this case, ArrayList vs. List<Object> then you won't notice any differences in speed. There might be some differences in the actual methods available on each of these, particular in .NET 3.5 and counting extension methods, but that has more to do with ArrayList being somewhat deprecated than anything else.

answered 2008-12-24T10:17:39.807
-5

List<> is a typesafe version of ArrayList. It will guarantee that you will get the same object type in the collection.

answered 2008-12-24T09:34:00.707

Your Answer