首页 新闻 赞助 找找看

c#多线程问题

0
[已关闭问题] 关闭于 2011-03-23 10:54
static List<string> list = new List<string>();    
    static void Main(string[] args)   
     {         
   new Thread(Go).Start();   
         new Thread(Go).Start();     
       Console.Read();      
  }        
static void Go()  
      {         
   for (int i = 0; i < 100; i++)    
        {         
       lock (list)     
               list.Add("Item" + list.Count);  
              string[] items;    
            lock (list)             
       items = list.ToArray();      
          foreach (string s in items)    
            {                
    Console.WriteLine(s);   
             }       
     }      
  }请问下这段代码为什么会先出来100以后的呢,
如果屏蔽掉一个线程,就会从56,57,然后就是0-99呢??
怪才博士的主页 怪才博士 | 初学一级 | 园豆:116
提问于:2011-03-22 23:25
< >
分享
所有回答(2)
0

帮顶

钢的锅 | 园豆:10 (初学一级) | 2011-03-23 02:53
0

这代码排版,让人怎么看?

麒麟.NET | 园豆:3614 (老鸟四级) | 2011-03-23 10:49
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册