views:

157

answers:

3

In C#, what's the syntax for declaring an indexer as part of an interface? Is it still this[ ]? Something feels odd about using the this keyword in an interface.

+2  A: 

It is - it's pretty odd syntax at other times if you ask me! But it works. You have to declare the get; and/or set; parts of it with no definition, just a semi-colon, exactly like ordinary properties in an interface.

Daniel Earwicker
+12  A: 
public interface IYourList<T>
    {
        T this[int index] { get; set; }
    }
Stan R.
+2  A: 

I know what you mean but, yes, this is correct. Here are the docs.

Ben Griswold