The class A with a Swap method. | Lecture 5 - slide 24 : 29 Program 1 |
using System; public class A{ private int a, b, c; public A(){ a = 1; b = 2; c = 3; } public void Swap(ref int v1, ref int v2){ int temp; temp = v1; v1 = v2; v2 = temp; } public override string ToString(){ return String.Format("{0} {1} {2}", a, b, c); } public void Go(){ Console.WriteLine("{0}", this); Swap(ref a, ref b); Swap(ref b, ref c); Console.WriteLine("{0}", this); } public static void Main(){ new A().Go(); } } | Two formal reference parameters Actual ref parameters must be variables! |