Which one is serializable - ArrayList (OR) List(Of String) ?


Can you please let me know which one is serializable and why - ArrayList (OR) List(Of String) ?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

milani_lucieAuthor Commented:
I thought that ArrayList can't be serialized. Please correct me if i am wrong.
ArrayList is serializable, Deathreace is correct. Even if you do not believe the forums about it, you can check so for yourself using Reflector (see screenshot), for instance, or easier, the F1 key in Visual Studio. The latter will show you this, which pretty much makes it Serializable:

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class ArrayList _
	Implements IList, ICollection, IEnumerable, ICloneable

Open in new window

Now, on the other part of your question, List(Of String) is also serializable. The reason however is slightly different. The List<T> uses the SerializableAttribute just the same way as any other Serializable class, but the caveat can be non-serializable members (in fact, that is just as true for ArrayList).

However, as always, any value type members, structs of value types (like DateTime) and strings are serializable by default and so neither of your approaches will have any serializability problems.

The choice should be List(Of Type) because that will give you a better performance (early binding) and easier coding (type safety/intellisense) and less errors (type safety).

-- Abel --

<SerializableAttribute> _
Public Class List(Of T) _
	Implements IList(Of T), ICollection(Of T),  _
	IEnumerable(Of T), IList, ICollection, IEnumerable

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.