有谁知道当使用 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)
我想对类型使用结构,但我有几个方法需要更改它。如果它装箱,我只会将其传递并返回它,或者可能使用一个类来代替。