C# language feature:

  • Out variables

applies to

  • method parameters

benefit

  • Allows declaring out variables at the point of passing to returning method.

how to use

  • Specify variable type after out keyword.

example:

        void Out_Variable_Example(string string2parse)
        {
            // int i; //previously int needed declaration like this
            bool parsed = int.TryParse(string2parse, out int i);
            if (parsed)
                System.Console.WriteLine($"the int is {i}");
            else
                System.Console.WriteLine("parse did not go well");
        }