Good introduction to generics
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 y开发者_如何学Pythonou have experience with generics: what resources did you find most useful learning them? (books, articles, etc...)
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).
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!
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.
I wrote 2 short articles about generics (mostly geared towards the List class)
http://dotnetchris.wordpress.com/?s=generics
精彩评论