c# - 实现索引器的接口(interface)

标签 c#

我正在寻找声明索引器的框架定义接口(interface)。换句话说,我在找东西 like this :

public interface IYourList<T>
{
    T this[int index] { get; set; }
}

我只是想知道.Net框架是否包含这样的接口(interface)?如果是,它叫什么?

您可能会问为什么我不能自己创建界面。好吧,我可以。但是,如果 .Net 框架已经有了,我为什么要重新发明轮子?

最佳答案

我认为您正在寻找 IList<T> .

从 MSDN 站点粘贴的示例:

T this[
    int index
] { get; set; }

编辑更多:

这是我刚刚 Reflected 的整个类,目的是向您展示接口(interface)在框架中的具体描述方式:

[TypeDependency("System.SZArrayHelper")]
public interface IList<T> : ICollection<T>, IEnumerable<T>, IEnumerable
{
    // Methods
    int IndexOf(T item);
    void Insert(int index, T item);
    void RemoveAt(int index);

    // Properties
    T this[int index] { get; set; }
}

关于c# - 实现索引器的接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2482826/

相关文章:

c# - 如何根据字符长度拆分字符串

c# - DirectoryInfo.ToString 在父目录上的工作方式不同?

c# - 当我尝试在我的网页中使用更新面板时,CSS 不工作?

c# - 在 Visual Studio 2012 中同时针对 x86 和 x64 平台

c# - 用递归求解有向图

c# - 如何添加用户 ID 以在 mvc4 中验证 cookie

c# - 如何在库上设置运行时绑定(bind)重定向

c# - 将派生类转换为 C# 中的另一个派生类

c# - 您能否预编译 C# 程序集以允许流畅的强类型、重构友好的代码并且具有高性能?

c# - 过滤 GroupJoin 查询