zoukankan      html  css  js  c++  java
  • linq中select和selectMany的区别

    linq Select与SelectMany的区别

     

    elect() 为每个源值生成一个结果值。因此,总体结果是一个与源集合具有相同元素数目的集合。与之相反,SelectMany() 将生成单一总体结果,其中包含来自每个源值的串联子集合。作为参数传递到 SelectMany() 的转换函数必须为每个源值返回一个可枚举值序列。然后,SelectMany() 将串联这些可枚举序列以创建一个大的序列。

    string[] text ={ "Albert was here", "Burke slept late", "Connor is happy" };  
    
    var tokens = text.Select(s => s.Split(''));
    
     foreach (string[] line in tokens)
    
          foreach (string token in line)        
    
          Console.Write("{0}.", token);
    
    
     
    string[] text ={ "Albert was here", "Burke slept late", "Connor is happy" };  
    var tokens = text.SelectMany(s => s.Split(''));  
    
    foreach (string token in tokens)    
    
      Console.Write("{0}.", token);

    用select的时候断点如图:

    用SelectMany的的调试结果:

    从断点调试的结果我们可以看出:

     Select() 为每个源值生成一个结果值。 因此,总体结果是一个与源集合具有相同元素数目的集合。 与之相反,SelectMany() 将生成单一总体结果,其中包含来自每个源值的串联子集合。 

    转自:https://www.cnblogs.com/tianyang1027/p/13932054.html

    本文来自博客园,作者:.net&new,转载请注明原文链接:https://www.cnblogs.com/wugh8726254/p/15196094.html

  • 相关阅读:
    day37 事务
    小组分享
    day36 pymysql 索引
    day 35 多表查询
    day 35 作业
    day 34 作业
    AST 节点类型对照表
    babel _shallowEqual.default
    js Proxy
    Symbol
  • 原文地址:https://www.cnblogs.com/wugh8726254/p/15196094.html
Copyright © 2011-2022 走看看