Information Technology Reference
In-Depth Information
Invoking a Generic Method
To invoke a generic method, supply type arguments with the method invocation, as shown here.
Type parameters
↓
MyMethod<short, int>();
MyMethod<int, long >();
Figure 19-11 shows the declaration of a generic method called
DoStuff
, which takes two
type parameters. Below it are two invocations of the method, with different sets of type param-
eters. Each invocation produces a different version of the method, as shown on the right of the
figure.
Figure 19-11.
A generic method with two instantiations