int x;
if (Q())
x = 123;
if (R())
Console.WriteLine(x); // illegal
int x;
if (Q())
x = 123;
if (false)
Console.WriteLine(x); // legal!!
May I know why second one is legal while former one is throwing ‘using unassigned local variable’ compile time exception?
This tells compiler that the condition under if in the statement given below will never execute, so the constraint of unused variable does not apply to it.