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...)
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With