如何申报有两个泛型类型参数的方法? [英] How to declare a Method with two generic type parameters?
问题描述
是否有可能做这样的事情有不同的泛型参数类型( U
)的函数的返回值,而已经有另外一个泛型参数类型牛逼
本地参数?
我曾尝试:
私有静态ü的someMethod< T,U>(T TYPE1,流S)
和
私有静态ü的someMethod< T>< U>(T TYPE1,流S)
编辑: 我们同意尝试:
私有静态ü的someMethod< T,U>(T TYPE1,流S)
公共静态牛逼someMethodParent< T>(流流)
{
ü东西=的someMethod(TYPE1,流);
...
}
私有静态ü的someMethod< T,U>(T TYPE1,流S)
是一个正确的语法。
http://msdn.microsoft。 COM / EN-US /库/ twcad0zb%28V = VS.80%29.aspx
由于JavaSa在评论中指出,需要提供实际的类型,如果他们不能被推断的形式使用,所以
私有静态üsomeMethodParent< T>(T类型1,流S)
{
返回的someMethod< T,ConcreteTypeConvertibleToU>(TYPE1,S);
}
Is it possible to do something like having different Generic Parameter type (U
) for a function return value, while already having another generic parameter type T
for local parameter?
I have tried:
private static U someMethod <T,U>(T type1, Stream s)
and
private static U someMethod <T><U>(T type1, Stream s)
Edit: We agreed to try:
private static U someMethod <T,U>(T type1, Stream s)
public static T someMethodParent<T>(Stream stream)
{
U something = someMethod(type1, stream);
...
}
private static U someMethod <T,U>(T type1, Stream s)
is a correct syntax.
http://msdn.microsoft.com/en-us/library/twcad0zb%28v=vs.80%29.aspx
As JavaSa stated in the comments, you need to provide the actual types if they cannot be inferred form the usage, so
private static U someMethodParent<T>(T Type1, Stream s)
{
return someMethod<T, ConcreteTypeConvertibleToU>(type1, s);
}
这篇关于如何申报有两个泛型类型参数的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!