Yes, List<object>
is a good replacement for ArrayList
.
If you want to have a list type that can hold anything, you can use either ArrayList
or List<object>
as the type of collection. It will have the same characteristics of performance and behavior.
The question is: why are you using an ArrayList
to get started? If you are using the predictive version of .NET, then you probably have no choice. You either have strongly typed arrays (which are constant in size), or you have an ArrayList
, which is dynamic in size, but overly "generic" in type. He can store anything.
Now, with the new versions of .NET and C #, it's time to leave it all.
(regarding comments on "net.NET and C # version": it is obvious that the "new" is not new here as in 2014, but compared to any textbook or source code that the OP learned from generics, it is "new" by compared to using ArrayList
.)
You want your collections to be strongly typed. This makes your life easier, as you know which fields / properties / members are available for collection items, etc.
Thus, you want to find out what the basic type of your elements is, and make a List<BaseType>
collection or similar, it will make your life a lot easier.
If you store a bunch of integers, use a List<int>
. If you keep a bunch of strings, use List<string>
. If you are storing a bunch of objects like SomeCustomObject
, use List<SomeCustomObject
.