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?
abelConnect With a Mentor Commented:
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

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.