I was wondering whether it is possible to use C#'s ref return
on (dictionary) indexers or properties which define a set
and get
accessor, e.g.:
readonly Dictionary<string, int> dictionary = ...;
ref int v = ref dictionary["foo"];
// ^^^^^^^^^^^^^^^^^^^^^
// CS0206: A property or indexer may not be passed as an out or ref parameter
v = 42;
Is it possible to somehow provide ref
functionality to properties or indexers (without using reflection)? If so, how?
I know, that the error message is clear in that sense - however, I was wondering which would be the optimal way to implement its semantics.