[英]Generic class with two type constraints, and a interface implementation
我偶然发现了一个小问题。 我正在尝试声明一个具有两个约束的泛型类,并且它还应该实现一个接口。 但是,问题在于,当我尝试在声明中获取接口时,它仅被视为两个泛型之一的约束。 如此处所示:
public class T_AccountControl<T, U>
where U : T_AccountView
where T : T_AccountModel, IAccountControl
{ ... }
我希望T_AccountControl <>实现IAccountControl。 Atm只是在T的约束链中。我曾尝试将其粘贴到T中,但似乎不起作用。
那么,我可以这样做吗? 还是因为某些其他原因而被禁止?
问候,Oyvind
在约束之前实施IAccountControl
:
public class T_AccountControl<T, U> : IAccountControl
where U : T_AccountView
where T : T_AccountModel
编辑:刚注意到您说过您尝试过“粘贴此类”。 不知道您做了什么,但是您可能有一个小错误,因为这应该对您有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.