using System; using System.Collections.Generic; using System.Threading; namespace MisleadingLambda { class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); List threads = new List(); for (int i = 0; i<10; ++i) { int j = i; // i is passed by refrence to the closure object, so, the value printed will be the index of the current // iteration in the main thread. Use j instead of i to print the thread number - j is a copy of a // well-defined value of i and won't ever change (next iteration will rather create a new j variable threads.Add(new Thread(() => { Console.WriteLine("i={0}", i); })); threads[i].Start(); } for (int i = 0; i < 10; ++i) { threads[i].Join(); } } } }