Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Should it not be
double value = default(double)
if(double.TryParse(input, out value))
{
// something here
} -
@itsdaniel0 Well, prior to C# 7.0, yes. Now you can just do that if you only need "value" inside of this particular if-block.
-
Oops, I accidentally forgot a closing ) for the if clause in my rant and noticed it way too late. woopsies
-
Actually not really correct. The variable declared that way is valid in the scope of the if, not the "then" scope.
This enables you to invert it like
if(!double.TryParse("5", out double d))
throw new IAmAngryException();
//do something with the d
Turns out
if(double.TryParse(input, out double value)
{
//Do something with value
}
can't be used in compilers using C# versions prior to 7.0. Reason: → out double value ←
...k den
undefined
and no online compilers support 7.0