From the same documentation:
variables entered by the template are similar to external variables described earlier
So actually this code:
if (!(o is int i)) return;
More or less equal:
int i; if (!(SomeParsingOn(o, out i))) return;
This means that i
declared at the same level as if
, which means that it is in the scope not only for if
, but also for the following operators. That this is true may be seens when copying if
:
if (!(o is int i)) return; // type pattern "int i" if (!(o is int i)) return; // type pattern "int i"
Gives error CS0128: A local variable with the name "i" is already defined in this area.
source share