ArrayList or List<>

  • Thread starter Thread starter csharpula csharp
  • Start date Start date
C

csharpula csharp

Hello,
I would like to know what is better for data binding and serialization
purposes ArrayList or List<> ? Thank you!
 
In both cases List<T>.
More importantly, you get compile-time safety and intellisense on your
code, which is worth quite a bit.

For binding:
The way the component-model detects the meta-data is complex; first,
it will detect collections via IListSource or IList (for the former it
just calls GetList() and ends with the latter). It then checks the
IList for ITypedList (to provide custom metadata), then if that isn't
implemented it checks for a "public Foo this[int index] {get;}"
indexer (for some Foo). If this is supported it uses the type of Foo
for the metadata. Failing that, it checks if the list has contents; if
it dose, it uses the first (index 0) item in the list to describe the
metadata. Finally it panics. (there is also specific handling of
arrays; probably immediately before the ITypedList check).

List<T> will therefore provide correct metadata (for type T) even when
the list is empty. ArrayList cannot.

For over-the-wire serialization, List<T> gives it at least a fighting
chance of providing schema metadata.

Marc
 
Marc said:
List<T> will therefore provide correct metadata (for type T) even when
the list is empty. ArrayList cannot.

For over-the-wire serialization, List<T> gives it at least a fighting
chance of providing schema metadata.

Also, for binding purposes, there is BindingList<T> that relieves a lot
of headaches. List<T> doesn't update things like ListView when its data
changes, so some events don't fire properly, whereas BindingList<T> does.

Just throwing that out there because I've run into it a couple of times.


Chris.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top