views:

134

answers:

4

Being compelled by the advantages I'm looking for a way to integrate generic programming into my current programming style. I would like to use generics in C# but can't find any good introductory material with some everyday examples of use. If you have experience with generics: what resources did you find most useful learning them? (books, articles, etc...)

+3  A: 

O'reilly article on generics

And I really enjoyed the generics part of the C# in Depth book by Jon Skeet, although it's not introductory but more ... in depth (as in read it when you're comfortable with generics to know a lot of interesting things about them, but not as an introduction).

Jorge Córdoba
Article is from 2005 and will likely confuse the OP. There's no reason to mention CLR or MSIL in an intro to generics article.
Ben S
"it's not introductory but more ... in depth."so you could say that it's not...generic?
Kevlar
Generics are from 2005. The CLR part might be a bit confusing but it covers it quickly, it's just an introduction so it not bad that it covers everything there's to know.
Jorge Córdoba
A: 

If you're going to be using C# and .NET, I'd recommend you go over the official docs, specifically, the Introduction to Generics Programming Guide.

These guides should be at the right level for you if you already know C#, but just want to brush up on generics. Lots of day-to-day code examples are also given throughout.

Ben S
+1  A: 

Honestly, I found just using the System.Collections.Generic classes to be the best starting point. If you aren't already, switch away from using the System.Collections classes to the new generic variants. That will get you used to the concepts. A strongly typed dictionary is a lovely thing.

After that it's not too much of a conceptual leap to create your own generic class. Intellisense is an amazing guide. Just start writing:

class Something<T> {
   T Item { get; set; }
}

And notice that your second "T" shows up in intellisense. Visual Studio is cheering you on! Hey, this is easy!

Eventually you'll exhaust the obvious and then will need a better resource. Google and MSDN has been all I've needed to date, but by the time you get beyond that and want a deeper understanding you'll already know enough to find the best books for your level of understanding.

Good luck!

roufamatic
A: 

I wrote 2 short articles about generics (mostly geared towards the List class)

http://dotnetchris.wordpress.com/?s=generics

Chris Marisic