static void Main(string[] args) { RefSwap x = new RefSwap(1, 2); RefSwap y = new RefSwap(3, 4); Console.WriteLine("До вызова"); Console.Write("x ->"); x.Show(); Console.Write("y ->"); y.Show(); Console.WriteLine("После вызова Swap"); x.Swap(ref x, ref y); Console.Write("x ->"); x.Show(); Console.Write("y ->"); y.Show(); Console.ReadLine(); }
static void Main() { RefSwap x = new RefSwap(1, 2); RefSwap y = new RefSwap(3, 4); Console.Write("x before call: "); x.Show(); Console.Write("y before call: "); y.Show(); Console.WriteLine(); // Exchange the objects to which x and y refer. x.Swap(ref x, ref y); Console.Write("x after call: "); x.Show(); Console.Write("y after call: "); y.Show(); }