Example #1
0
// }
        static void Main(string[] args)
        {
            #region OUT_PARAMS
            /* OLD Syntax */
            int a, b;
            Point.GetPoint().GetCoordinates(out a, out b);
            PrintMessage("OUT PARAMS", $"My coordinates: ({a}, {b})");

            /* C# 7.0 (Inline statement & var keyword is available) */
            Point.GetPoint().GetCoordinates(out var x, out var y);
            PrintMessage("OUT PARAMS", $"My coordinates: ({x}, {y})");

            #endregion

            #region DECONSTRUCTION                 // { autofold
            (var myX, var myY) = Point.GetPoint(); // Will call Point.Deconstruct(...)
            // Other valid syntax
            // (var myX1, _) = Point.GetPoint();
            // (_, var myY2) = Point.GetPoint();
            // var (myX3, myY3) = Point.GetPoint();

            PrintMessage("DECONSTRUCTION", $"Syntax (var myX, var myY) : [{myX}, {myY}]");
            #endregion  // }

            #region REF // { autofold
            RefTest refExample = new RefTest();

            int copy = refExample.Find(3); copy++;            // Here, we increment a local variable.
            PrintMessage("REF", $"Without ref: refExample.Read(3) = {refExample.Read(3)}");

            ref int reference = ref refExample.FindRef(3); reference++; // Here, we increment the ref.
Example #2
0
    static void Main()
    {
        RefTest ob = new RefTest();
        int     a  = 10;

        Console.WriteLine("a before call: " + a);
        ob.Sqr(ref a); // notice the use of ref
        Console.WriteLine("a after call: " + a);
    }
Example #3
0
    public static void Main()
    {
        RefTest ob = new RefTest();
        int     a  = 10;

        Console.WriteLine("а перед вызовом: " + a);
        ob.sqr(ref a); // Обратите внимание
                       //на использование модификатора ref.
        Console.WriteLine("а после вызова: " + a);
    }
    public static void Main()
    {
        RefTest rt1 = new RefTest();
        RefTest rt2 = new RefTest();

        rt1.Value = 1;
        rt2.Value = 2;
        Console.WriteLine("rt1.Value = " + rt1.ToString());
        Console.WriteLine("rt2.Value = " + rt2.ToString());

        rt1       = rt2;
        rt1.Value = 3;

        Console.WriteLine("rt1.Value = " + rt1.ToString());
        Console.WriteLine("rt2.Value = " + rt2.ToString());
    }