程序园

弹奏键盘人生,拂去青春的尘土,留下的只有岁月的痕迹
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

.net 3.5 where 的另类用法

Posted on 2010-05-05 23:00  程旭圆  阅读(276)  评论(0编辑  收藏  举报

命名空间:  System.Linq
程序集:  System.Core(在 System.Core.dll 中)

List<string> fruits =
                new List<string> { "apple", "passionfruit", "banana", "mango",
                                "orange", "blueberry", "grape", "strawberry" };

            IEnumerable<string> query = fruits.Where(fruit => fruit.Length < 6);

            foreach (string fruit in query)
            {
                Console.WriteLine(fruit);
            }
            /*
             This code produces the following output:

             apple
             mango
             grape
            */