The value for setting an indexer shouldn't be used as the second argument. The get
simply has no access to a set value, as there is none. In the set
method there is a contextual keyword, value
, that has the value set to the indexer:
public class MyIndexer
{
private Dictionary <int,string> testdctnry = new Dictionary<int,string>();
public string this[int index]
{
get
{
if (index > 0)
MessageBox.Show("Hey m Zero");
return testdctnry[index];
}
set
{
if (index > 1)
MessageBox.Show("Setting up");
testdctnry[index] = value;
}
}
}