Is there a C# LINQ syntax for the Queryable.SelectMany() method?

后端 未结 3 1165
别跟我提以往
别跟我提以往 2020-12-08 06:32

When writing a query using C# LINQ syntax, is there a way to use the Queryable.SelectMany method from the keyword syntax?

For

string[] text = { \"Al         


        
相关标签:
3条回答
  • 2020-12-08 06:59

    Yes, you just repeat the from ... in clause:

    var words = from str in text
                from word in str.Split(' ')
                select word;
    
    0 讨论(0)
  • 2020-12-08 07:01

    Your query would be re-written as:

    var tokens = from x in text
                 from z in x.Split(' ')
                 select z;
    

    Here's a good page that has a couple of side-by-side examples of Lambda and Query syntax:

    Select Many Operator Part 1 - Zeeshan Hirani

    0 讨论(0)
  • 2020-12-08 07:13

    You can use a Compound from Clause:

    var tokens = from s in text
                 from x in s.Split(' ')
                 select x;
    
    0 讨论(0)
提交回复
热议问题