嗨,我正在尝试做两个对象的简单交换.我的代码是
void Main()
{
object First = 5;
object Second = 10;
Swap(First, Second);
//If I display results it displays as
//Value of First as 5 and Second as 10
}
private static void Swap(object First, object Second)
{
object temp = First;
First = Second;
Second = temp;
}
Run Code Online (Sandbox Code Playgroud)
由于对象是引用类型,因此应将其引用传递给方法,并且应该交换.为什么不发生?