given the following code:
string example = "1234";
long parsed_example = long.Parse(example);
Console.Writeline(parsed_example);
# => 1234
Works great.
the following example does not:
string example = "";
long parsed_example = long.Parse(example);
# [System.FormatException: Input string was not in a correct format.]
However the goal is:
string example = "";
if (example == "")
{
example = "0";
}
long parsed_example = long.Parse(example);
Console.Writeline(parsed_example);
# => 0
is there a shorter, apropriate solution? The above code would almost justify a tiny function, Id preferable have a inline solution. Maybe something such as (pseudo code):
string example = "";
long parsed_example = example ?? 0, long.Parse(example);