Linq学习from let where子句

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/*from let where子句
 * 1、from 后面接的是查询主体,可以有任何数量个,指定了额外的数据集合并引入了要在之后运算的迭代变量
 * 2、let子句接受一个表达式的运算并且把它赋值给一个需要在其他运算中使用的标识符。
 * 3、where子句根据之后的运算来除去不符合指定条件的项
 */
namespace from_let_where
{
    class Program
    {
        static void Main(string[] args)
        {
            var GroupA = new[] { 3, 4, 5, 6 };
            var GroupB = new[] { 4, 5,6,7};
            var someInt1 = from int a in GroupA
                          from int b in GroupB
                          where a>4&&b<=8
                          select new { a, b, sum=a+b};//匿名类型变量
            foreach (var a in someInt1)
                Console.WriteLine(a);
            var someInt2 = from int a in GroupA
                          from int b in GroupB
                          let sum = a + b
                          where sum >= 11
                          where a == 4
                          select new { a, b, sum };
            foreach (var a in someInt2)
                Console.WriteLine(a);
            Console.ReadKey();
        }
    }
}
posted @ 2015-09-14 20:15  Alfred.Xu  阅读(369)  评论(0编辑  收藏  举报