Loading

LINQ TakeWhile 和 Where 的区别

View Code
var intList = new int[] { 1, 2, 3, 4, 5, -1, -2 };
Console.WriteLine("Where");
foreach (var i in intList.Where(x => x <= 3))
    Console.WriteLine(i);
Console.WriteLine("TakeWhile");
foreach (var i in intList.TakeWhile(x => x <= 3))
    Console.WriteLine(i);
Where
1
2
3
-1
-2
TakeWhile
1
2
3

 

posted @ 2013-03-28 20:22  青岛欧姆网络科技  阅读(318)  评论(0编辑  收藏  举报