Resharper的Access to Modified Closure
警告通常非常有用。我只是注意到当我在每个循环中调用Any
方法时,如果我不使用open和close括号,我会收到警告。只要我添加()
,错误就会消失。
错误本身是否消失,或者我只是偶然欺骗了Resharper的静态代码分析检测。
Dim groupExists as Boolean
For each oldPerson in oldData
'access to modified closure warning on oldPerson.groupId
groupExists = (From newPerson In newData
Where newPerson.GroupId = oldPerson.groupId).Any
'no closure problem reported
groupExists = (From newPerson In newData
Where newPerson.GroupId = oldPerson.groupId).Any()
Next
当然,我可以通过将以下代码放在For Each
循环中并将newPerson.GroupId
与本地声明的变量进行比较来解决此问题。
'declare locally to avoid access to modified closure
Dim groupId as Integer = person.groupId
答案 0 :(得分:3)
我认为这是一个Resharper错误,我会在那里提交。在linq语句中不能立即执行修改后的闭包,就像Any
那样。
VB不是我的'母语',但是假设括号不应该对VB.Net产生任何影响(就像在VB6中那样)。