June 2008
Intermediate to advanced
784 pages
20h 36m
English
Generic methods have type parameters. These parameters can be used in the method header or body. An open method has type parameters, which are nonspecific. A closed method has type arguments, where specific types are substituted for type parameters. For a generic method, the type parameters are listed after the function name. The type parameter list is enclosed in angle brackets. Each parameter is comma-delimited.
Here is a sample generic method:
using System;
namespace Donis.CSharpBook {
public class Starter {
public static void Main() {
ZClass.MethodA<int>(20);
}
}
public class ZClass{
public static void MethodA<T>(T param) {
Console.WriteLine(param.GetType().ToString());
}
}
}When calling a generic method, insert the type arguments ...
Read now
Unlock full access