int.TryPrase is great and all, but there is only one problem...it takes at least two lines of code to use:
int intValue;
string stringValue = \"
This answer is only for those who use at least C# 7.
You can now declare the out parameter inline.
int.TryParse("123", out var result);
Exemplary usage:
if (int.TryParse("123", out var result)) {
//do something with the successfully parsed integer
Console.WriteLine(result);
} else {
Console.WriteLine("That wasn't an integer!");
}
MSDN: https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7#out-variables