Indexer as part of the interface in C#

大憨熊 提交于 2019-12-22 05:06:30

问题


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.


回答1:


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



回答2:


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.




回答3:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!