Thursday, September 19, 2013

to control the behavior of the [] associative array

to control the behavior of the [] associative array

public class MyClass
{
    public string this[string someArg]
    {
        get { return "You called this with " + someArg; }
    }

}

class Program
{

    void Main()
    {
        MyClass x = new MyClass();
        Console.WriteLine(x["something"]);
    }
}

Reference:
http://stackoverflow.com/questions/12391745/does-c-sharp-have-array-with-index-is-a-string-like-php

No comments: