Given the method
ref readonly State GetState();
where State is a struct, the following code accesses State.SimTime without copying State:
ref readonly var state = ref GetState();
var t = state.SimTime;
Meanwhile this code does copy State:
var start = GetState();
var t = state.SimTime;
My question is whether the following copies State:
var t = GetState().SimTime;
My hope is that it doesn't, since the result of GetState() is a ref and never assigned, but I don't know for sure and don't know how I would test for it.
As a bonus, is there a way to inspect code staticcally to determine whether memory is copied?
getasreadonly, and that makes a huge difference to the answer.