How does the ref keyword work (in terms of memory)

后端 未结 4 2020
广开言路
广开言路 2021-02-12 13:48

C# has a ref keyword. Using ref you can pass an int to a method by reference. What goes on the stack frame when you call a method that accepts an int by reference?



        
4条回答
  •  日久生厌
    2021-02-12 14:08

    The address of the local variable or field. In the IL, ldloca.s instruction is used for a local variable.

    Loads the address of the local variable at a specific index onto the evaluation stack

    The stind instruction is used to store the value back in the variable

    Store value of type (...) into memory at address

    The address is 32/64 bit, depending on target architecture.

提交回复
热议问题