Do int ref parameter get boxed?

后端 未结 6 1914
-上瘾入骨i
-上瘾入骨i 2021-02-12 13:14

Say I have the following code:

void Main()
{
    int a = 5;
    f1(ref a);
}

public void f1(ref int a)
{
    if(a > 7) return;
    a++;
    f1(ref a);
    Co         


        
6条回答
  •  走了就别回头了
    2021-02-12 13:25

    It is not a boxing.

    There is clear explanation in MSDN ref keyword documentation:

    Do not confuse the concept of passing by reference with the concept of reference types. The two concepts are not the same. A method parameter can be modified by ref regardless of whether it is a value type or a reference type. There is no boxing of a value type when it is passed by reference.

提交回复
热议问题