zoukankan      html  css  js  c++  java
  • 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() 将生成单一总体结果,其中包含来自每个源值的串联子集合。 

  • 相关阅读:
    PHP的错误和异常处理
    PHP 页面编码声明方法详解(header或meta)
    Sentinel实现Redis高可用
    Linux学习系列之Iptables
    Python学习系列之logging模块
    [scrapy]Item Loders
    [scrapy]实例:爬取jobbole页面
    mongo开启验证
    python创建虚拟环境
    elastalert邮件报警
  • 原文地址:https://www.cnblogs.com/tianyang1027/p/13932054.html
Copyright © 2011-2022 走看看