看这里:
static void Main(string[] args)
{
test p = new test();
new Thread(() => p.SayHello("Thread One")).Start();
new Thread(() => p.SayHello("Thread Two")).Start();
}
然后:
class test
{
public void SayHello(string data)
{
int i = 0;
while (i < 50)
{
Console.WriteLine("Hello from " + data);
i++;
}
}
}
为什么第二个线程不将变量重置i
为 0?并弄乱它在第一个线程上运行的while循环?