1

If wonder why the compiler does not allow me to write the following:

if (someCondition && double.TryParse(astring, NumberStyles.Any, CultureInfo.InvariantCulture, out double v))
{
    // CS0165   Use of unassigned local variable 'v'
    // Seems incorrect, evaluating the conditions will never leave the variable unassigned
}

While it's perfectly fine to write

if (double.TryParse(astring, NumberStyles.Any, CultureInfo.InvariantCulture, out double v))
{
    // No compiler warning, the out parameter is always set
}

Why does the compiler not allow me to write the first example?

update

the input was a string, but was stored in a dynamic property. Damien_The_Unbeliever already pointed out the question which already explains what this means.

bas
  • 13,550
  • 20
  • 69
  • 146

0 Answers0