2.linq延迟执行

延迟执行:一般情况下,Linq查询表达式由3部分组成,即数据源、查询操作、和执行查询。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] arr = { "Shenzhen","xian","nanjing","Shanghai","beijing","Chongqing"};
            IEnumerable<string> strs = from s in arr
                                       where s.Length > 7  //对象的长度大于7的
                                       orderby s  ascending  //升序
                                       select s; //获取对象集合
            foreach (var s in strs)  //循环对象
            {
                Console.WriteLine(s);
            }

        }
    }
}

 

posted @ 2016-11-13 23:33  狼牙者.net  阅读(106)  评论(0)    收藏  举报