zoukankan      html  css  js  c++  java
  • 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();
            }
        }
    }
  • 相关阅读:
    LeetCode翻转矩阵后的得分-Python3<六>
    LeetCode子域名访问计数-Python3.7<五>
    LeetCode 键盘行-Python3.7<四>
    流程控制<二>
    Numbers、Strings、Lists 笔记<一>
    LeetCode-数组操作-Python<三>
    LeetCode链表相加-Python<二>
    LeetCode两数之和-Python<一>
    使用Django创建网站项目<二>
    Windows下vue-cli脚手架搭建入门<一>
  • 原文地址:https://www.cnblogs.com/sulong/p/4808096.html
Copyright © 2011-2022 走看看