Now that C# supports ref return values, is there some way (or alternative) to use List<T>
where T
is a value type and get ref from the indexer? From the documentation it seems that it returns simply T
, which means that there is no way to update a structure in place without copying it out of the list, updating, and copying back in.
Is there any way to use List<T>
while getting a ref indexer, or some alternative data structure that does the same? I'm aware that it is possible to do this with arrays, but I'm looking for a dynamic growable array.
Looking at the examples given in this documentation and this blog post, arrays support ref return
values via indexer, but List<T>
doesn't (I have tried).
So I don't think there is anyway to use ref return
on the list indexer until it is implement in the framework.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With