See question in commented code...
public struct Key
{
public string Name;
public object Value;
}
public class PrimaryKey
{
Dictionary<string, Key> _keys = new Dictionary<string, Key>();
object this[string index]
{
get
{
return _keys[index].Value;
}
set
{
if (!_keys.ContainsKey(index))
_keys.Add(index, new Key() { Name = index, Value = value });
else
{
var k = _keys[index]; // This compiles
k.Value = value; // just fine.
_keys[index].Value = index; // So why wouldn't this?
}
}
}
}
I get the error:
Cannot modify the return value of
Dictionary<string,Key>.this[string]
because it is not a variable