PC Review


Reply
Thread Tools Rate Thread

ArrayList or List<>

 
 
csharpula csharp
Guest
Posts: n/a
 
      26th Nov 2007
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 ***
 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      26th Nov 2007
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
 
Reply With Quote
 
Chris Shepherd
Guest
Posts: n/a
 
      27th Nov 2007
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
about List<T> and ArrayList Tony Johansson Microsoft C# .NET 0 9th Nov 2010 10:52 AM
ArrayList vs. List puzzlecracker Microsoft C# .NET 12 16th Oct 2008 10:49 PM
migrating to List<T> from ArrayList David C Microsoft C# .NET 6 20th May 2008 11:09 PM
Populate Combo/List Box with ArrayList Greg Microsoft VB .NET 4 19th Apr 2008 08:33 PM
ArrayList vs. List<> Zytan Microsoft C# .NET 44 17th May 2007 12:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:42 PM.