我进行了一些ref
关键字的测试,有一件事我不太明白:
static void Test(ref int a, ref int b)
{
Console.WriteLine(Int32.ReferenceEquals(a,b));
}
static void Main(string[] args)
{
int a = 4;
Test(ref a, ref a);
Console.ReadLine();
}
为什么这段代码显示False
?我知道int
是一个值类型,但这里应该传递对同一对象的引用。
ref
修饰符不会导致相应的参数被装箱为引用类型。 - Lee