Chapter 12: Generics


Overview

One of the (admittedly few) criticisms leveled against the first version of C# was its lack of support for generics. Generics in C++ (known as templates in that language) had long been regarded as an excellent way of doing things, allowing a single type definition to spawn a multitude of specialized types at compile time and thus saving an awful lot of time and effort. For whatever reason, generics didn't quite make it into the first release of C#, and the language suffered because of it. Perhaps this was so because generics are often seen as being quite difficult to come to grips with, or maybe it was decided that they weren't necessary. Thankfully though, with C# version 2.0 generics have come to join the party. And no, they aren't really that difficult to use, although they do require a slightly different way of looking at things. The end result of your efforts, though, will be richly rewarded!

In this chapter, you:

  • Look at what a generic is. You learn about generics in fairly abstract terms at first, since learning the concepts behind generics is crucial to being able to use them effectively.

  • See some of the generic types in the .NET Framework in action. This will help you to understand more about their functionality and power, as well as the new syntax required in your code.

  • Define your own generic types. This will include generic classes, interfaces, methods, and delegates. You also see additional techniques for further customizing generic types: the default keyword and type constraints.




Beginning Visual C# 2005
Beginning Visual C#supAND#174;/sup 2005
ISBN: B000N7ETVG
EAN: N/A
Year: 2005
Pages: 278

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net