简体   繁体   中英

How can i call generic T type method in c#

I have method

public static T GetUrlDataEntity<T>(){}

and i want to call this method in my another class how can i call this method in c#.

You have to specify a type argument. For example:

string x = TypeDeclaringMethod.GetUrlDataEntity<string>();

The MSDN documentation on generic methods has more details.

Note that in this case, you can't use type inference as the method has no parameters which use T . If your method were:

public static T DoSomething<T>(T input)

then you'd be able to get the compiler to infer the type argument, eg

int x = 10;
int y = DoSomething(x);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM