Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Generics - why all the fuss? Explained.

I have just never really understood all the fuss about Generics (the upcoming feature in 2.0).  Maybe it is because I have never used templates in C++ or done anything meaningful in C++ for that matter! :)  

At the moment, I derive from the System.Collections.CollectionBase and System.Collections.DictionaryBase abstract classes to easily create strongly typed collections when I need them.  This approach is poor for performance due to all the casting required but this is seldom a problem in business applications where bigger bottlenecks can typically be found elsewhere and to-the-metal performance is seldom a concern.

Today I came across Generics In-Depth by J. Ambrose Little - our editor-in-chief at AspAlliance.  Ambrose goes beyond the typical "strongly typed stack" example that we have all seen in the demos and shows constraints, type inference, discusses limitations and even makes comparisons to Java's upcoming generics (1.5).  He also provides some advanced code samples to show generics in use.  This article is a great read.

What uses do you have for generics?  Do you use CollectionBase and DictionaryBase now (presentations on Generics seldom mention them)?

1 Comment

  • From what I understand, generics will let you have strongly type collections (among other things) without having to explicitly define a new collection class for each type. You just define one for all similar based collections. I think it will shorten coding quite a bit. There are other reasons I've heard of (haven't played around with it all yet unfortunately) but this sounds like one of the biggest advantages for me.

Comments have been disabled for this content.