简体   繁体   中英

Doubly Generic Types in C#

I'm new to C#, so sorry for the syntax question, but I can't find the answer anywhere. I'm trying to make a type with the following type-architecture

public abstract class MyAbstractType {...}
public class MyFirstType : MyAbstractType {...}
public class MySecondType : MyAbstractType {...}

public abstract class AbstractHeap<T> {...}
public class MyFirstHeap : AbstractHeap<MyFirstType> {...}
public class MySecondHeap : AbstractHeap<MySecondHeap> {...}

public class MetaHeap<T1,T2> : AbstractHeap<T1> where T2 : AbstractHeap<T3> where T3 : MyAbstractType {...}

The last definition is the one giving me the problems. Is it just a syntax problem that I don't realize, or is this kind of structure not allowed in C#?

You're almost there. There are three type parameters in this declaration, but you put only two in the MetaHeap<> braces and forgot T3 .

public class MetaHeap<T1,T2,T3> : AbstractHeap<T1> 
    where T2 : AbstractHeap<T3> 
    where T3 : MyAbstractType {...}

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