When you write an if
without braces, the compiler treats the single statement as if there were braces, so:
if (node != null)
string fullAddress = node.InnerText;
essentially gets turned into:
if (node != null)
{
string fullAddress = node.InnerText;
}
However, note that the scope of fullAddress
is only within the braces, so the variable can never be used. The compiler is smart enough to know this, and so it flags it as an error because it knows that no sane programmer would ever do this. :)
I think this is actually a common theme in the .NET compilers - they have a lot of sanity checking to make sure you don't do something that doesn't make sense, and will often optimize their output based on various code patterns.