首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

linq的小的有关问题

2013-02-17 
linq的小的问题本帖最后由 xzgspchina 于 2013-02-01 14:56:25 编辑string[] namenew string[1000]for (

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);

热点排行