|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ArrayList or List<>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 *** 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 Gravell wrote:
> List<T> will therefore provide correct metadata (for type T) even when Also, for binding purposes, there is BindingList<T> that relieves a lot > the list is empty. ArrayList cannot. > > For over-the-wire serialization, List<T> gives it at least a fighting > chance of providing schema metadata. 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. |
|||||||||||||||||||||||