开发者

Interface that Entails the Implementation of Indexer

I am looking for a framework-defined interface that declares indexer. In other words, I am looking for something like this:

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

I just wonder whether .Net framework contains such interface? 开发者_运维问答If yes, what is it called?

You might ask why I can't just create the interface myself. Well, I could have. But if .Net framework already has that why should I reinvent the wheel?


I think you're looking for IList<T>.

Sample pasted from the MSDN site:

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

EDIT MORE:

This is the entire class I just Reflected to show you exactly how the interface is described in the framework:

[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; }
}


I am not aware of such an interface in the BCL.


There is no interface that only implements an indexer (generic or otherwise).

The closest you can get is use some of the collection interfaces, such as IList.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜