C# what is the point or benefit of an indexer?

后端 未结 11 2093
暖寄归人
暖寄归人 2020-12-16 16:07

Doing some code reading and stumbled upon this snippet that I haven\'t seen before:

public SomeClass {
  public someInterface this[String strParameter] {
            


        
11条回答
  •  攒了一身酷
    2020-12-16 16:38

    Well you could use this method in a key-value pair class.

    I am not sure what the analogous class is in c#, but in c++ STL, there is the map class where you call the method with the SomeObject["key"] and it will return the "value" associated with that key.

提交回复
热议问题