当前位置: 代码迷 >> LINQ >> linq的小的有关问题
  详细解决方案

linq的小的有关问题

热度:2884   发布时间:2013-02-26 00:00:00.0
linq的小的问题
本帖最后由 xzgspchina 于 2013-02-01 14:56:25 编辑

 string[] name  =new string[1000];
            for (int i = 0; i < 1000; i++)
            {
                name[i] = i.ToString();
            }

            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            IEnumerable<string> storName = from n in name
                                           where (n.Length == (from n1 in name
                                                               orderby n1.Length
                                                               select n1.Length).First()
                                                 )
                                           select n;
            foreach (string s in storName)
            {
                Console.WriteLine(s);
            }
            stopwatch.Stop();
              Console.WriteLine(stopwatch.Elapsed);
            Console.ReadLine(); 


以上代码在控制台运行上面name的长度为1000的时候走红色的部分。。
超过10000时就不走了(断点就是不进去)。。为什么
很郁闷。。
linq

------解决方案--------------------------------------------------------
不会,肯定走,你是不是很慢啊
------解决方案--------------------------------------------------------
IEnumerable<string> storName = name.Where(n => n.Length == name.First().Length);
  相关解决方案