C# Feature - Out variables
Overview
Section titled “Overview”Out variables allow inline declaration of out arguments, reducing the need for separate variable setup lines.
Introduced In
Section titled “Introduced In”C# 7.0 (2017)
Before
Section titled “Before”int number;if (int.TryParse(text, out number)){ Console.WriteLine(number);}if (int.TryParse(text, out int number)){ Console.WriteLine(number);}Gotchas & Best Practices
Section titled “Gotchas & Best Practices”- Use discards when the parsed value is not needed.
- Keep the variable scope small by declaring it inline.