Skip to content

C# Feature - Out variables

Out variables allow inline declaration of out arguments, reducing the need for separate variable setup lines.

C# 7.0 (2017)

int number;
if (int.TryParse(text, out number))
{
Console.WriteLine(number);
}
if (int.TryParse(text, out int number))
{
Console.WriteLine(number);
}
  • Use discards when the parsed value is not needed.
  • Keep the variable scope small by declaring it inline.