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.