Why does resharper suggest “wrap variable in array” for access to modified closure warnings?
- 阅读更多 关于 Why does resharper suggest “wrap variable in array” for access to modified closure warnings?
问题 Given the following (heavily edited, pseudo-)code: int count = 0; thing.Stub(m => m.AddBlah()).WhenCalled(o => count++); thing.Stub(m => m.RemoveBlah()).WhenCalled(o => count--); DoStuff(thing); Assert.AreEqual(1, count); ReSharper provides a warning on count - "Access to modified closure". I understand why I'm getting this warning (the count variable is being modified in two different lambdas, and is likely to have undesirable semantics), but I don't understand ReSharper's advice: "Wrap