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