LINQ ForEach method skips Console.WriteLine() on each iteration, then dumps all the logs when loop is done. Why?
Advertisements I have this piece of code: [Test] public void LinqConsoleOutputTest() { Enumerable.Range(0, 10).ToList().ForEach(_ => { Thread.Sleep(500); Console.WriteLine($"Slept…"); }); } And to my surprise the code was executing around 5 seconds as expected, but it did not print to the console. It just dumped all 10 logs when it finished ForEach loop. And I am… Read More LINQ ForEach method skips Console.WriteLine() on each iteration, then dumps all the logs when loop is done. Why?