Created
May 5, 2018 21:17
-
-
Save christiannagel/15be025ef469521bc9b12ed7dcc74d94 to your computer and use it in GitHub Desktop.
out var with C# 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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