Do int ref parameter get boxed?

后端 未结 6 1920
-上瘾入骨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

    I think you are mistaken in saying the int parameter is being boxed. From MSDN,

    Boxing is the process of converting a value type to the type object or to any interface type implemented by this value type

    What you have here is an int parameter being passed by reference, specifically it's a "value type" being passed by reference.

    You can refer to Jon Skeet's excellent explanation on parameter passing for details.

提交回复
热议问题