Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Did you know that you can call a generic method with out supplying the type argument. The C# compiler will fill in the type parameter for you at compile time since the language is strongly typed.
static void MyMethod<S>(S myParam)
{
Console.WriteLine(typeof(S).ToString());
Console.WriteLine(myParam.GetType().ToString());
}
static void Main(string[] args) {
int a1 = 5;
object a2 = 5;
MyMethod(a1);
MyMethod(a2);
} /* //Outputs: System.Int32 System.Int32 System.Object System.Int32 */
Comments
- Anonymous
December 16, 2007
PingBack from http://geeklectures.info/2007/12/16/did-you-know-generic-methods/