How can I both get and set a value in an object in my indexer?
DataIdxer_Instance[3].Accum += 123000;
Error - cannot modify the return value of ...DataIdxer.this[int] Because it is NOT a variable.
public class DataIdxer
{
protected ArrayList Datas = new ArrayList();
public DataObj this[int idx]
{
get
{
if (idx > -1 && idx < Datas.Count)
{
return ((DataObj)Datas[idx]);
}
else
{
throw new InvalidOperationException("[Data indexer get item] index out of range");
}
}
set
{
if (idx > -1 && idx < Datas.Count)
{
Datas[idx] = value;
}
else if (idx == Datas.Count)
{
Datas.Add(value);
}
else
{
throw new InvalidOperationException("[Datas indexer set item outofrange]");
}
}
}
}
public struct DataObj
{
public Int64 Accum;
public DataObj(int D)
{
Accum = D;
}
}