Skip to content
Discussion options

You must be logged in to vote

Yes, pattern variables and out declarations within a while loop condition do not leak to the outer scope. This was an explicit decision based on the propensity that a capturing lambda within the loop body would enclose over the single leaked variable scope and not the value of the variable within the loop. That was a common source of confusion and bugs with capturing in foreach loops to the extent that the team was willing to accept a breaking change to the language to resolve, so they didn't want to repeat that mistake.

https://github.com/dotnet/csharplang/blob/master/meetings/2016/LDM-2016-11-30.md#scope-of-while-condition-expression-variables
dotnet/roslyn#15529

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by CyrusNajmabadi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants