This code shows how to use reference paameters in c#
class Test { static void Swap(ref int x, ref int y) { int t = x; x = y; y = t; } static void Main() { int a = 1; int b = 2;
Console.WriteLine("pre: a = {0}, b = {1}", a, b); Swap(ref a, ref b); Console.WriteLine("post: a = {0}, b = {1}", a, b); } } The output of the program is: pre: a = 1, b = 2 post: a = 2, b = 1
|
No responses found. Be the first to respond and make money from revenue sharing program.
|