I recently installed VS2013 (alongside a previous VS2010 installation) and noticed I no longer receive the compiler warning 'BC42324' (text below) when compiling identical VB.NET code (I recompiled back in VS2010 to confirm warning is still shown):
Using the iteration variable in a query expression may have unexpected results. Instead, create a local variable within the loop and assign it the value of the iteration variable.
Documentation on MSDN seems to suggest the warning is still included. I see/don't-see the warning with the following code :
Dim Numbers = {0, 1}
For Each index In Numbers
Dim SumPlusIndex = Aggregate x In Numbers Select x + index Into Sum()
Next
Has this warning genuinely been removed? Is so how come? If not could there be other environmental differences between my VS2010 and VS2013 installation that might cause the difference?
Yes, that's the infamous capture the for loop variable bug. It has bitten many programmers so Microsoft decided to do something about it. They solved it for a For Each loop, but not a For loop. You can still trigger the warning like this:
Sub Main()
For ix As Integer = 1 To 10
Dim dlg = Sub()
Console.WriteLine(ix) '' Eek!
End Sub
'' etc...
Next
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With