I want an Indexer but types of the setter and the getter should be different.
public Foo this[string key]
{
get
{
return FindFoo(key);
}
}
public Bar this[string key]
{
set
{
DoMagic(key, value);
}
}
When I try:
myClass["hello"] = coolBar;
It says: The call is ambiguous
Is there anyway to do this?
You can't do that, basically - not when the two indexers have the same signature.
Even if you could, I'd say it would be a pretty odd design, which would surprise users of your API.
The relevant bit of the C# specification is section 10.9: