【问题标题】:Indexer - Explicit Interface Member Implementation索引器 - 显式接口成员实现
【发布时间】:2017-12-10 17:38:52
【问题描述】:

我需要一个索引器的显式接口成员实现的工作示例程序。

Microsofts c# docu of Indexers 声明这是可能的,但没有提供一个工作示例(至少对我来说这个示例不起作用)。我需要一个可以做到这一点的工作程序。

【问题讨论】:

  • “对我来说,这个例子不起作用”。什么不工作?你得到什么错误?这似乎是非常简单直接的代码,所以如果它不起作用,请展示您尝试过的内容。

标签: c# interface indexer explicit-interface


【解决方案1】:

文档似乎有误。我现在无法检查它,我不记得曾经明确实现过索引器,但这应该可以工作:

interface IInterface
{
    ReturnType this[int index] { get; }
}

class Foo: IInterface
{
    ReturnType IInterface.this[int index]
    {
        get { return ... }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-08
    • 1970-01-01
    • 2017-05-11
    • 2023-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-19
    相关资源
    最近更新 更多