3 ms·
This was a concern of mine as well, as you can see in the discussion of scope changes for pattern variables [1], the C# checks for definite assignments handle t
by Eyas 10y ago
This was a concern of mine as well, as you can see in the discussion of scope changes for pattern variables [1], the C# checks for definite assignments handle this. So:
if (o is int i) { f(i); }
use_int(i); // <-- error: variable `i` is not definitely assigned
But then if you have:
if (o is int i || (o is string s and int.TryParse(out i)) use_int(i);
We know that `i` is definitely assigned at that location.
[1]: https://github.com/dotnet/roslyn/issues/12597 https://github.com/dotnet/roslyn/issues/12597