In C#7 there is an improvement on using out parameter. Some of you may remember writing code like below.
|
string hourString = "5"; int hour; if (int.TryParse(hourString, out hour)) { Console.WriteLine($"The hour is {hour}"); } |
The improvement that C#7 brings is you can now declare out variables in the argument list of a method call, rather than writing a separate declaration statement like below:
|
string hourString = "5"; if (int.TryParse(hourString, out int hour)) { Console.WriteLine($"The hour is {hour}"); } |
And it doesn’t end there […]