为什么实例化一个新的int会更改此代码的输出?

时间:2018-06-29 01:27:20

标签: c#

下面的代码返回以下输出:

(('GB', 'United Kingdom'), ('AU', 'Australia'), ('AT', 'Austria'), ('BE', 'Belgium'), ('CA', 'Canada'), ('DK', 'Denmark'), ('FI', 'Finland'), ('FR', 'France'), ('DE', 'Germany'), ('HK', 'Hong Kong'), ('IE', 'Ireland'), ('IT', 'Italy'), ('LU', 'Luxembourg'), ('NL', 'Netherlands'), ('NZ', 'New Zealand'), ('NO', 'Norway'), ('PT', 'Portugal'), ('SG', 'Singapore'), ('ES', 'Spain'), ('SE', 'Sweden'), ('CH', 'Switzerland'), ('US', 'United States'))

enter image description here

只需添加int j = i,它将输出完全更改为我期望的值,这是达到信号量限制的正确响应:

Semaphore sema = new Semaphore(5,5,"sema_1");
for (int i = 0; i < 10; i++)
{
    ThreadPool.QueueUserWorkItem(delegate(object state)
    {
        sema.WaitOne();
        Console.WriteLine(" = " + i);
        sema.Release();
    });
}

enter image description here

0 个答案:

没有答案