具有泛型的约束语法,也源自类

发布于 2024-11-09 00:01:00 字数 237 浏览 7 评论 0原文

我遇到了以下问题:我有一个带有约束的泛型类,它派生自非泛型接口:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一身软味 2024-11-16 00:01:00

那么就不要让它成为约束的一部分。

约束应该出现在继承声明之后:

public abstract class DrilldownBase<W> : IDrilldown where W : class, 

Don't make it part of the constraint then.

The constraint should come after the inheritance declaration:

public abstract class DrilldownBase<W> : IDrilldown where W : class, 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文