码迷,mamicode.com
首页 > 其他好文 > 详细

Linq学习from let where子句

时间:2015-09-14 20:54:54      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:

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

Linq学习from let where子句

标签:

原文地址:http://www.cnblogs.com/sulong/p/4808096.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!