开发者

how to create generic object for a class

开发者 https://www.devze.com 2023-02-19 04:04 出处:网络
How do I create a function which will accept generic object of cla开发者_StackOverflow社区ss as an argument and will also havea generic return type?If you want the same generic for the input and retur

How do I create a function which will accept generic object of cla开发者_StackOverflow社区ss as an argument and will also have a generic return type?


If you want the same generic for the input and return types then:

public T DoSomething<T>(T input)

If you want different generics for the input and return types then:

public TReturn DoSomething<TInput, TReturn>(TInput input)


like this:

 public T Method<T>(T param)

the method may take as manay generic parameters as are needed to specify the types of the various input and return parameters, so you may also do this:

public T1 Method<T1,T2,T3>(T1 input1, T2 input2, T3 input3);

some information on generic methods on MSDN

0

精彩评论

暂无评论...
验证码 换一张
取 消