接口属性协变覆盖的语法是什么?

发布于 2025-01-09 23:55:41 字数 640 浏览 4 评论 0原文

根据规范此处< /a>,

接口方法、属性和索引器覆盖

<块引用>

通过在 C# 8.0 中添加 DIM 功能,添加了接口中允许的成员类型,我们进一步添加了对覆盖成员以及协变返回的支持.

我试图让以下协变覆盖起作用,但我找不到语法示例。你能帮忙吗?

public interface IFoo{}
public interface IFuzz:IFoo{}

public interface IBar
{
    IFoo Foo {get;}
}

public interface IBaz:IBar
{
    //override IFuzz IBar.Foo Foo {get;}  //This syntax isn't correct.
}

也许我误解了规范?帮助!

According to the specification here,

Interface Method, Property, and Indexer Override

Adding to the kinds of members that are permitted in an interface with the addition of the DIM feature in C# 8.0, we further add support for override members along with covariant returns.

I am trying to get the following covariant override to work, but I can't find an example of the syntax. Can you help?

public interface IFoo{}
public interface IFuzz:IFoo{}

public interface IBar
{
    IFoo Foo {get;}
}

public interface IBaz:IBar
{
    //override IFuzz IBar.Foo Foo {get;}  //This syntax isn't correct.
}

Maybe I am misinterpreting the specification? Help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

合约呢 2025-01-16 23:55:41

哦。我没有清楚地阅读规范。如果您遇到同样的问题(截至 2022 年 2 月),请参阅上面引用的部分:

下面的规范草案的其余部分提出了对接口方法的协变返回的进一步扩展,稍后将予以考虑。

它还不存在。

Doh. I didn't read the specification clearly. If you come across the same issue (as of February 2022), this prefaces the above quoted section:

The remainder of the draft specification below proposes a further extension to covariant returns of interface methods to be considered later.

It doesn't exist yet.

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