zoukankan      html  css  js  c++  java
  • LINQ

    一. Where  :选择行.

    隐藏行号 复制代码 这是一段程序代码。
    1. IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate);
      
     IEnumerable<TSource> Where<TSource>(f => 一个条件表达式)
    隐藏行号 复制代码 这是一段程序代码。
    1. public static IEnumerable<TSource> Take<TSource>(this IEnumerable<TSource> source, int count);
      

    Take : 选择行

    a.task(5)  //选择前5行.

    例:

    List.Where(f => typeof(Csla.Core.IPropertyInfo).IsAssignableFrom(f.FieldType))

     

    红色部分既可以是一条语句,也可以是一段代码块{…},代码块里面有一个返回值. List中有过少个元素.

    则这条语句/代码块就执行多少此.

    里面的表达式不不会立即执行,只是什么时候需要使用返回值的时候才执行ladm表达式.

     

     

    隐藏行号 复制代码 这是一段程序代码。
    1. static void Main(string[] args)
      
    2. {
      
    3.     List<int> nList = new List<int>();
      
    4.     IEnumerable<int> sFilter;
      
    5.     int nCount;
      
    6.     nList.Add(1);
      
    7.     nList.Add(2);
      
    8.     nList.Add(3);
      
    9.     nList.Add(4);
      
    10.     nList.Add(5);
      
    11.     nList.Add(6);
      
    12.     nList.Add(7);
      
    13.     nList.Add(8);
      
    14.     nList.Add(9);
      
    15.     nList.Add(10);
      
    16.     nList.Add(11);
      
    17.     sFilter = nList.Where(f => 
      
    18.         {  //有多少个元素,这个代码块就执行多少此.
      
    19.          if (f > 5)
      
    20.          {
      
    21.              if (f.Equals(10))
      
    22.              {
      
    23.                  return true;
      
    24.              }
      
    25.          }
      
    26.          else
      
    27.          {
      
    28.              return false;
      
    29.          }
      
    30.          return false;
      
    31.          });
      
    32.     nCount = sFilter.Count();   //这里才开始执行Where中的代码块.
      
    33. 
      
    34. }
      

    二.Select  //选择列.

    隐藏行号 复制代码 这是一段程序代码。
    1. public static IEnumerable<TResult> Select<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector);
      

    IEnumerable<CSLAPropertyInfo>.Select(f=>{代码块…})

    隐藏行号 复制代码 这是一段程序代码。
    1. private static IEnumerable<CSLAPropertyInfo> LoadFromType(Type type)
      
    2. {
      
    3.     var staticFields = type.GetFields(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
      
    4.     return staticFields.Where(f => typeof(Csla.Core.IPropertyInfo).IsAssignableFrom(f.FieldType))
      
    5.         .Select(f =>
      
    6.         {
      
    7.             bool isChild = false;
      
    8.             var property = f.GetValue(null) as Csla.Core.IPropertyInfo;
      
    9.             //判断是不是孩子对象
      
    10.             var fieldType = f.FieldType;
      
    11.             if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(PropertyInfo<>))
      
    12.             {
      
    13.                 var argType = fieldType.GetGenericArguments()[0];
      
    14.                 while (argType.BaseType != null)
      
    15.                 {
      
    16.                     if (argType.IsGenericType && argType.GetGenericTypeDefinition() == typeof(GBusinessListBase<,>))
      
    17.                     {
      
    18.                         isChild = true;
      
    19.                         break;
      
    20.                     }
      
    21.                     argType = argType.BaseType;
      
    22.                 }
      
    23.             }
      
    24.             return new CSLAPropertyInfo(property, isChild);
      
    25.         });
      
    26. }
      

  • 相关阅读:
    Navigator与UserAgent笔记
    linux常用命令 查看文件
    linux常用命令 ps
    linux grep命令详解
    svn突然不能用了!
    Macrotask Queue和Microtask Quque
    base.css
    跨域资源共享 CORS 详解
    react按需加载(getComponent优美写法),并指定输出模块名称解决缓存(getComponent与chunkFilename)
    更新阶段的生命周期
  • 原文地址:https://www.cnblogs.com/SouthAurora/p/1710336.html
Copyright © 2011-2022 走看看