Graviton
Graviton

Reputation: 83326

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?

Upvotes: 7

Views: 846

Answers (3)

Codesleuth
Codesleuth

Reputation: 10541

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

Upvotes: 5

Oded
Oded

Reputation: 499402

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.

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1039598

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

Upvotes: 0

Related Questions