First time here? Check out the site's "greatest hits" or read a post from the archives. Feel free to leave a comment or ask a question, and consider subscribing to the latest posts via RSS or e-mail. Thanks for visiting!
« Medtronic Minimed 508 Insulin Pump vs. m... | Main | Oh yes, it kicks much booty - Just rippe... »

Wesner offers his thoughts on my question, What's the difference between System.Collections.Generic.Collection and System.Collections.Generic.List?

I think there are two possible reasons.

  • Collection<T> appears to be a replacement for CollectionBase, which provided virtual methods to detect insertions, deletions and changes.
  • The new List class no longer provides any virtual methods as did the original ArrayList for performance reasons..
    [Wesner Moise]

He also educates us on some of the differences between List<T> and the 2.0 ArrayList.

  • List<T> does not use any virtual methods. As a result, a number of methods such as the list indexer methods can now be inlined.
  • With the default constructor, List<T> and Whidbey ArrayList do not allocate any memory for its items, so an empty list represents a very compact object--comparable in size to an empty array. (8 bytes for Array, 12 bytes for List, 16 bytes for Whidbey ArrayList) It uses the empty array trick that I wrote about in an earlier post. In contrast, earlier versions of ArrayList would allocate space for 16 items by default.
  • The initial buffer size when an item is actually added is 4 items not 16 as before.
  • List<T> returns an struct-based enumerator, so that iterating through foreach now involves no memory allocations at all.
    [Wesner Moise]



Monday, August 02, 2004 10:45:13 AM (Pacific Standard Time, UTC-08:00)
Did you see this post from the BCL Team?
http://blogs.msdn.com/bclteam/archive/2004/07/29/201059.aspx

In particular,
"System.Collections namespace now contains collections intended for scenarios where a collection needs to be exposed from an object model. For example Directory.Files property returning a collection of files in a directory. The collections are called Collection[T], ReadOnlyCollection[T], and KeyedCollection[K,T]."

BTW, I replaced the lt/gt with square brackets because the site gave me a request validation exception message when I saved the comment.

Tuesday, August 03, 2004 4:36:55 AM (Pacific Standard Time, UTC-08:00)
Why No comments posted yet?
Tuesday, August 03, 2004 8:19:22 AM (Pacific Standard Time, UTC-08:00)
I was wondering the same thing.
Scott Hanselman
Comments are closed.

Contact

Sponsors

Hosting By

On this page...

Tags

Calendar

<January 2009>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

Archives

Google Ads