C# overloading index operator

class MyClass
{
  private readonly Dictionary<string,object> data = new Dictionary<string,object>();
  public object this [string index]
  {
    set{ data[index] = value; }
    get{ return data[index]; }
  }
  
  public static void Main()
  {
    MyClass me = new MyClass();
    me["test"] = "sample value";
    Console.WriteLine(me["test"]);
  }
}

Comments

Popular posts from this blog

Parse XML to dynamic object in C#

C# Updating GUI from different thread