Difference Between Select and SelectMany

后端 未结 17 1288
长情又很酷
长情又很酷 2020-11-22 05:21

I\'ve been searching the difference between Select and SelectMany but I haven\'t been able to find a suitable answer. I need to learn the differenc

17条回答
  •  不要未来只要你来
    2020-11-22 05:25

    It's more clear when the query return a string (an array of char):

    For example if the list 'Fruits' contains 'apple'

    'Select' returns the string:

    Fruits.Select(s=>s) 
    
    [0]: "apple"
    

    'SelectMany' flattens the string:

    Fruits.SelectMany(s=>s)
    
    [0]: 97  'a'
    [1]: 112 'p'
    [2]: 112 'p'
    [3]: 108 'l'
    [4]: 101 'e'
    

提交回复
热议问题