This is a mirror of official site: http://jasper-net.blogspot.com/

Extended Generic Collection From Absolute Zero

| Tuesday, March 9, 2010
Introduction

I decided to try my hand at a custom generic collection class, and started looking into the implementations of the generic collection classes, such as List<T> or the interfaces like ICollection<T>. But while what I found as I went along was useful information, ultimately one question rose above all others as I looked at example after example of simple and complex implementations of CollectionBase or ICollection<T> that at its core just wrapped an ArrayList or List<T> internally, which to me defeats the purpose of implementing a baser class or interface in the first place. If you could write a class that wraps a List<T> successfully why bother with implementing ICollection or IList if you could just put a List<T> in your class? What if I didn't want to wrap an existing structure that is more advanced than the more primitive interfaces I was considering? What options are there?

Background

Eventually I ended up with my own collection class, which I think could still be useful even in the age of 3.0 - HashSet<T> is a speedy unique-value list that can beat my collection on Contains checks for unique values but it relies on being unique and cannot sort, and List<T> is slightly faster than my collection on Sorts, but not by much. Neither one still natively provide a single-value sorted unique-value list. (See Benchmarks near the end for actual numbers)

Even if it is rendered obsolete by extending a List<T> to add a Unique function, I think it's still good information to know, I had never broken down a collection to this level before and picked up a few new concepts.

Read more: Codeproject

Posted via email from jasper22's posterous

0 comments: