My Links

Archives

Post Categories

Generic Collecions In .NET 2.0

I'm starting to dig into Generics and collections for the Tourney Bracket Control. We have a number of collections that we use, and before, we had a lot of (generated) code wrapped into those collections. With generics, we can eliminate most of that code.

Each of our collections has an "Owner" property, which allows us to walk the bracket hierarchy - go from a round to it's containing group, or from a match up to it's containing round. Based on these requirements, I need to have a custom collection and can't use a generic list, but I still want the maintainability of generics. Well, it turns out you can inherit from a generic collection and make a typed collection:

MyTypedCollection : System.Collections.Generic.List<MyTypedObject>

You can inherit from a generic collection, specifying a particular type when you do so. Now I can add my methods and properties that I need for each collection. I cut my collections down from a few 100 lines of code to less than 20. Nice!

posted on Friday, June 03, 2005 8:03 PM

sales@tourneylogic.com Copyright © Joel Ross