CollectionBase vs. ArrayList

Published 10 July 06 12:26 AM | adrian

 Or in Generic realms, Collection<T> vs. List<T>.

What's the big deal between the two of them, we'll see:

Comparison

CollectionBase

ArrayList

Implemented Interfaces

ICollection, IEnumerable, IList

ICollection, IEnumerable, IList

Number of Members

18; 5 public, 13 protected

58; all public

Intended Usage

As a base class for extension

Ready-to-use

Extra notes: CollectionBase was widely used pre-Generic for it's strong typing capabilities. ArrayList doesn't have this. But since Generic, List<T> is strong typable, too.

Conclusion: if you're looking for a ready-to-use IList implementation, use ArrayList (or List<T>), and if you're going to extend IList, use CollectionBase.

Anyone up for a speed comparison challenge?

Share this post: | | | |
Filed under:

Comments

# adrian said on July 10, 2006 09:41 AM:

Just want to add something to the discussion. Do you know that Collection's default constructor is this? :)

public Collection()
{
this.items = new List<T>();
}

# adrian said on July 10, 2006 07:08 PM:

Speed ? List<T>.. No question