使用 ref 关键字传递给方法时,结构体是否被装箱?

use*_*580 5 c# struct ref parameter-passing

有谁知道当使用 ref 关键字将结构传递给方法时是否会发生装箱

struct Test
{
    public int Value;
}

static void Main()
{
    Test test = new Test();
    SomeMethod(ref test);
    System.Diagnostics.Debug.WriteLine(test.Value);
}

static void SomeMethod(ref Test test)
{
    test.Value = 5;
}
Run Code Online (Sandbox Code Playgroud)

我想对类型使用结构,但我有几个方法需要更改它。如果它装箱,我只会将其传递并返回它,或者可能使用一个类来代替。

SLa*_*aks 3

不,不是。

相反,会传递结构在内存中的位置。

但是,不要这样做
可变结构是邪恶的