多线程问题
有哪位高手能解释下,为什么会出现这样的结果?
static void Main(string[] args) { for (int i = 0; i < 10; i++) { new Thread(() => { Console.WriteLine(i); }).Start(); } //输出结果如下: //2 //2 //4 //4 //6 //6 //6 //9 //9 //10 for (int i = 0; i < 10; i++) { int temp = i; new Thread(() => { Console.WriteLine(temp); }).Start(); } //输出结果如下: //0 //2 //1 //3 //4 //6 //5 //7 //8 //9 Console.ReadKey(); }