简体   繁体   中英

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> .

It tried defining C just like that but I get

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

public A/B (T t)

Your generic type declaration is okay, but your parameterless constructor doesn't have a counterpart in A<T> .

You should call the base class' constructor with the parameters it requires.

Something like:

public C() : base("param1", "param2", 3)
{
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM