Type Parameters (Methods)

Download c# eBook

Example

Declaration:

void MyGenericMethod<T1, T2, T3>(T1 a, T2 b, T3 c)
{
    // Do something with the type parameters.
}

Invocation:

There is no need to supply type arguements to a genric method, because the compiler can implicitly infer the type.

int x =10;
int y =20;
string z = "test";
MyGenericMethod(x,y,z);

However, if there is an ambiguity, generic methods need to be called with type arguemnts as

MyGenericMethod<int, int, string>(x,y,z);

Stats

Contributors: 2
2016-08-12
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook