zoukankan      html  css  js  c++  java
  • Linq 学习

    查询表达式:

    1常用的Linq字句:from(要查找的数据源),select(指定查询要返回的目标数据),where(指定查询的筛选条件),orderby(升序倒叙),group(指定元素的分组字段),Join(指定多个数据源的关联方式)

    1.1:from字句:from localval in dataSource

    var query = from intval in array select intval+1;
               foreach (int val in query)
                 {
                     Console.WriteLine("{0}", val);
                 }
                 Console.ReadLine();

    1.2:select字句:from localval in dataSource select expression

    expression是一个表达式,用来计算要作为查询结果的元素

    //用数据源中所有的元素创建一个匿名类型
                var query = from intval in array select new {Intval=intval,Doublevalue=intval*1.5 };
                foreach (var item in query)
                 {
                     Console.WriteLine(item);
                 }
                 Console.ReadLine();

    1.3 where字句:from localval in dataSource where condition select expression

    //用数据源中所有的元素创建一个匿名类型
                var query = from intval in array where (intval>30&&intval<80)select new {Intval=intval,Doublevalue=intval*1.5 };
                foreach (var item in query)
                 {
                     Console.WriteLine(item);
                 }
                 Console.ReadLine();

    where intval>30 where intval<80==where (intval>30&&intval<80)

    1.4:orderby 字句:orderby expression [sortType]

    expression 是要进行排序的表达式,可以是from字句中的localval。sortType是可选参数(ascending 升序)(desending 降序)

     var query = from intval in array  orderby intval descending select new {Intval=intval,Doublevalue=intval*1.5 };
                foreach (var item in query)
                 {
                     Console.WriteLine(item);
                 }
                 Console.ReadLine();

  • 相关阅读:
    高精度模板 支持各种运算 c++
    404 页面不存在
    多柱汉诺塔问题“通解”——c++
    高精度gcd
    404 页面不存在
    如何开启音乐二倍速?不下载其他软件【win10】
    如何随时学习数学
    洛谷P1004 方格取数
    Title
    Title
  • 原文地址:https://www.cnblogs.com/zhang123/p/3394307.html
Copyright © 2011-2022 走看看