
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Understanding Generic Types
|
225
Console.WriteLine(gB);
GenericClass<string> gC = new GenericClass<string>( );
Console.WriteLine(gC);
GenericClass<string> gD = new GenericClass<string>( );
Console.WriteLine(gD);
The output from the preceding code shows this:
There are 1 instances of CSharpRecipes.Generics+StandardClass which contains 0
items of type System.Object[]...
There are 2 instances of CSharpRecipes.Generics+StandardClass which contains 0
items of type System.Object[]...
There are 3 instances of CSharpRecipes.Generics+StandardClass which contains 0
items of type System.Object[]...
There are 1 instances of CSharpRecipes.Generics+GenericClass`1[System.Boolean]
which contains 0 items of type System.Boolean[]...
There are 1 instances of CSharpRecipes.Generics+GenericClass`1[System.Int32]
which contains 0 items of type System.Int32[]...
There are 1 instances of CSharpRecipes.Generics+GenericClass`1[System.String]
which contains 0 items of type System.String[]...
There are 2 instances of CSharpRecipes.Generics+GenericClass`1[System.String]
which contains 0 items of type System.String[]...
Discussion
The type parameters in generics allow you to create type-safe code without knowing
the final type you will be working with. In many instances you want the types to
have certain characteristics,