[英]Generic Compound Types in C#
I have the generic types A<T>
and B<T>
and now I want to construct the type C<T> : A<B<T>>
which as you can see is a very specific kind of A<T>
. 我有通用类型
A<T>
和B<T>
,现在我想构造C<T> : A<B<T>>
类型C<T> : A<B<T>>
,如您所见,它是一种非常特殊的A<T>
。
It tried defining C
just like that but I get 它试图那样定义
C
,但是我得到了
The type `A<B<T>>' does not contain a constructor that takes `0' arguments
Just in case I built the constructor 以防万一我构建了构造函数
public C () {}
but I still get the error. 但是我仍然得到错误。
Note: This is an abstraction of the problem. 注意:这是问题的抽象。 Assume that A and B have a constructor with the form
假设A和B具有以下形式的构造函数
public A/B (T t)
Your generic type declaration is okay, but your parameterless constructor doesn't have a counterpart in A<T>
. 泛型类型声明是可以的,但是您的无参数构造函数在
A<T>
中没有对应的构造函数。
You should call the base class' constructor with the parameters it requires. 您应该使用所需的参数调用基类的构造函数。
Something like: 就像是:
public C() : base("param1", "param2", 3)
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.