Chapter 17: Introducing Generics


Chapter 17

Introducing Generics

After completing this chapter, you will be able to:

  • Define a type-safe class by using Generics.

  • Create instances of a generic class based on types specified as type-parameter.

  • Implement a generic interface.

  • Define a generic method that implements an algorithm independent of the type of data that it operates on.

In Chapter 8, “Understanding Values and References,” you learned how to use the object type to refer to an instance of any class. You can use the object type to store a value of any type, and you can define parameters by using the object type when you need to pass values of any type into a method. A method can also return values of any type by specifying object as the return type. Although this practice is very flexible, it puts the onus on the programmer to remember what sort of data is actually being used and can lead to run-time errors if the programmer makes a mistake. In this chapter, you will learn about Generics, a feature that has been added to C# 2.0 to help you prevent these kinds of mistakes.




Microsoft Visual C# 2005 Step by Step
Microsoft® Visual C#® 2005 Step by Step (Step By Step (Microsoft))
ISBN: B002CKYPPM
EAN: N/A
Year: 2005
Pages: 183
Authors: John Sharp

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