Skip to content

Instantly share code, notes, and snippets.

@christiannagel
Created May 5, 2018 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christiannagel/15be025ef469521bc9b12ed7dcc74d94 to your computer and use it in GitHub Desktop.
Save christiannagel/15be025ef469521bc9b12ed7dcc74d94 to your computer and use it in GitHub Desktop.
out var with C# 7
// C# 6
string n = "42";
int result;
if (string.TryParse(n, out result)
{
Console.WriteLine($"Converting to a number was successful: {result}");
}
// C# 7
string n = "42";
if (string.TryParse(n, out var result)
{
Console.WriteLine($"Converting to a number was successful: {result}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment