The foreach identifier and closures

前端 未结 7 1377
误落风尘
误落风尘 2020-11-22 10:51

In the two following snippets, is the first one safe or must you do the second one?

By safe I mean is each thread guaranteed to call the method on the Foo from the s

7条回答
  •  花落未央
    2020-11-22 11:13

    Both are safe as of C# version 5 (.NET framework 4.5). See this question for details: Has foreach's use of variables been changed in C# 5?

提交回复
热议问题