[英]Type parameter with type argument in C# Generics
I want to use a type parameter with type argument in generics in c# like this:我想在 C# 中的泛型中使用带有类型参数的类型参数,如下所示:
public class ClassB {}
public class ClassA<T>: IList<T<ClassB>> {}
Is it possible doing something like this?有可能做这样的事情吗?
After trying many things, it seems you can't yet, even using where
clauses: the compiler refuses all T<ClassB>
and IList<T1<T2>>
.在尝试了很多事情之后,似乎你还不能,甚至使用
where
子句:编译器拒绝所有T<ClassB>
和IList<T1<T2>>
。
https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs0307 https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs0307
Example:例子:
public class ClassA<T1, T2> : IList<T1<T2>> // implementation request refused
where T2 : ClassB
{
}
public class ClassA<T, T1, T2> : IList<T>
where T : T1<T2> // constraint refused
where T2 : ClassB
{
}
Cannot use parameter of type T1 with arguments of type
不能将 T1 类型的参数与类型的参数一起使用
It might be interesting to be able to do such a thing.能够做这样的事情可能会很有趣。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.