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.
public interface IYourList<T>
{
T this[int index] { get; set; }
}
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.
I know what you mean but, yes, this is correct. Here are the docs.
来源:https://stackoverflow.com/questions/1223490/indexer-as-part-of-the-interface-in-c-sharp