[英]Doubly Generic Types in C#
I'm new to C#, so sorry for the syntax question, but I can't find the answer anywhere.我是 C# 新手,很抱歉出现语法问题,但我在任何地方都找不到答案。 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#?这只是我没有意识到的语法问题,还是 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
.此声明中有三个类型参数,但您只将两个放在MetaHeap<>
大括号中而忘记了T3
。
public class MetaHeap<T1,T2,T3> : AbstractHeap<T1>
where T2 : AbstractHeap<T3>
where T3 : MyAbstractType {...}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.