我有以下的类和方法:如何在泛型的where子句中指定泛型类?
public class MyGenericClass<T>
where T : class
{
}
public class MyClass
{
public TGen MyMethod<TGen>(TGen myGenClass)
where TGen : MyGenericClass<T>
where T : class
{
return myGenClass;
}
}
然而,这给出了一个错误,因为它无法化解的MyMethod符号T
。我宁愿不必有MyMethod<TGen, T>
,因为它对我来说似乎有点多余。这可能吗?
但是'MyMethod'中没有'T'类型的参数。我不明白你想要做什么。 – 2012-04-19 16:01:44
我想有'公共TGen MyMethod(TGen myGenClass)其中TGen:MyGenericClass <>' –
cm007
2012-04-19 16:03:01
我再次,我不明白你想用'MyGenericClass <>'传达什么。你为什么认为'MyGenericClass'的类型参数会以任何方式被推断?推断出什么? – 2012-04-19 16:04:01