具有泛型的约束语法,也源自类
我遇到了以下问题:我有一个带有约束的泛型类,它派生自非泛型接口:
public abstract class DrilldownBase<W> where W : class, IDrilldown
这段代码不正确,因为它认为 IDrilldown 是一个约束,而它不是。我想要的是 DrilldownBase 类继承自 IDrilldown。我缺少什么?
谢谢。
I'm having a heck of an issue with the following: I have a generic class, with a constraint, that derives from a non-generic interface:
public abstract class DrilldownBase<W> where W : class, IDrilldown
This code is not correct through, because it thinks IDrilldown is a constraint, when its NOT. What I want is for the class DrilldownBase to inherit from IDrilldown. What am I missing?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那么就不要让它成为约束的一部分。
约束应该出现在继承声明之后:
Don't make it part of the constraint then.
The constraint should come after the inheritance declaration: