C# – Closures capture variables, not values
Let’s say you’re firing off Task.Run() a bunch of times in a loop and passing in the loop variable, like this: The natural assumption is that this will print out 0 through 9. But instead, it’s printing out ten 10’s: This is a common mistake, especially when using Task.Run() in a loop. What’s happening here … Read more