1
ReSharper的Access to Modified Closure
警告通常是相當有幫助的。我只是注意到,當我打電話的Any
方法的內部for each循環,我會,如果我不使用的打開和關閉括號得到一個警告。當我加入()
,錯誤消失。爲什麼訪問修改關閉警告消失時可枚舉的方法調用()
是否錯誤本身消失,或者我只是不小心被騙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