References

Up to now you've seen how basic applications can be implemented easily. In those applications, we accessed variables directly and modified them without worrying about anything else.

However, in many cases, it's necessary to pass values to other procedures. This usually isn't a problem, but in some cases it leads to some new circumstances that you have to deal with:

using System;

public class Demo
{
        public static void Main()
        {
                int x = 3;
                int y = 5;

                Swap(x, y);
                Console.WriteLine("x: {0} - y: {1}", x, y);
        }

        static void Swap(int a, int b)
        {
                int c = a;
                a = b;
                b = c;
                Console.WriteLine("a: {0} - b: {1}", a, b);
        }
}

We define two variables inside the main program. The target of the method called Swap is to change the content of those values. ...

Get Mono Kick Start now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.