Home All Groups Group Topic Archive Search About
Author
26 Nov 2007 12:56 PM
csharpula csharp
Hello,
I would like to know what is better for data binding and serialization
purposes ArrayList or List<> ? Thank you!



*** Sent via Developersdex http://www.developersdex.com ***

Author
26 Nov 2007 1:08 PM
Marc Gravell
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
Author
27 Nov 2007 5:36 PM
Chris Shepherd
Marc Gravell wrote:
> 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.

AddThis Social Bookmark Button