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

  • 相关阅读:
    php设计模式-简单依赖注入容器的闭包方式实现
    php设计模式-简单依赖注入容器
    php设计模式-简单依赖注入
    php设计模式-数据对象映射
    php设计模式-迭代器
    php设计模式-接口工厂模式
    可变数量参数*args 关键字可变数量参数**kwargs
    python文本文件读写
    excel文件处理
    wxPython 使用总结
  • 原文地址:https://www.cnblogs.com/zhang123/p/3394307.html
Copyright © 2011-2022 走看看