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

  • 相关阅读:
    单工-半双工-双工
    为你的Windows7设置动态壁纸
    Vmware为Ubuntu安装VmTools
    CodeBlocks集成cppcheck
    自定义鼠标右键(层叠式菜单:cascading menu)
    Hao123这个流氓
    Android的ADT内容助手快捷方式设置
    安装Google框架服务并突破Google Play下载限制
    Windows7下CHM电子书打开不能正常显示内容
    谷歌首页背景设置
  • 原文地址:https://www.cnblogs.com/zhang123/p/3394307.html
Copyright © 2011-2022 走看看