By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,492 Members | 1,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,492 IT Pros & Developers. It's quick & easy.

ArrayList or List<>

P: n/a
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 ***
Nov 26 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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<Twill therefore provide correct metadata (for type T) even when
the list is empty. ArrayList cannot.

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

Marc
Nov 26 '07 #2

P: n/a
Marc Gravell wrote:
List<Twill therefore provide correct metadata (for type T) even when
the list is empty. ArrayList cannot.

For over-the-wire serialization, List<Tgives it at least a fighting
chance of providing schema metadata.
Also, for binding purposes, there is BindingList<Tthat relieves a lot
of headaches. List<Tdoesn't update things like ListView when its data
changes, so some events don't fire properly, whereas BindingList<Tdoes.

Just throwing that out there because I've run into it a couple of times.
Chris.
Nov 27 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.