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

后端 未结 11 2106
暖寄归人
暖寄归人 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:17

    That's called an Indexer, they allow you to use List<>, ArrayList, Dictionary<> and all the other collections using an array syntax.

    It's just syntactic sugar, but it gives some readability when used right.

提交回复
热议问题