public class DicTestClass
{
public DicTestClass(int a)
{
mAA = a;
}
public int mAA = 0;
}
public static void SwapRightListItem(ref DicTestClass left, ref DicTestClass right)
{
DicTestClass temp = null;
temp = right;
right = left;
left = temp;
}
static void Main(string[] args)
{
DicTestClass aaa = new DicTestClass(1);
DicTestClass bbb = new DicTestClass(2);
SwapRightListItem(ref aaa, ref bbb);
Console.WriteLine(" aaa:" + aaa.mAA);
Console.WriteLine(" bbb:" + bbb.mAA);
}
上面的代碼:輸出值是2,1? ?如果全去掉ref? 輸出值是1,2? ?
為什么?? ?class不已經(jīng)是引用類型了嗎???
C# swap ref 的問題
慕工程0101907
2018-12-07 02:47:09