I have a ConcurrentStack<int>
, and I'm doing this:
while (!stack.TryPop(out int res)) {
}
Console.WriteLine(res); // This doesn't work, res is not found
However, for some reason, the compiler can't find res
. If I switch it to a simple if
statement, it works:
if (!stack.TryPop(out int res)) {
}
Console.WriteLine(res); // Works
This seems quite odd, as the if
syntax is almost the same as the while
syntax.
I'm using C# 7.2
.