Is there any possible way to make a property that uses an indexer other than one global one for the whole class? Here's the gist of what I want to do. Note that in this example, you should pretend I cannot move data
or create another Dictionary
.
class MyClass
{
protected Dictionary<string,object> data = new Dictionary<string,object>();
public object Foo[int index]
{
get {
string name = String.Format("foo{0}",index);
return data[name];
}
}
public object Bar[int index]
{
get {
string name = String.Format("bar{0}",index);
return data[name];
}
}
}
I would then be able to reference an item of the data
named foo15
or bar12
like so
MyClass myClass = new MyClass();
Console.WriteLine(myClass.Foo[15]);
Console.WriteLine(myClass.Bar[12]);
I'm aware you can do this, but this isn't what I want.
public object this[string index]
{
get {
return data[index];
}
}