LINQ - Get all items in a List within a List?

后端 未结 4 896
梦如初夏
梦如初夏 2021-02-18 16:28

I\'m currently working my way through the learning curve that is LINQ and I could really use some assistance. I don\'t know if what I want is possible, but if I had to wager, I

相关标签:
4条回答
  • 2021-02-18 16:57

    You want to use the SelectMany extension method.

    _tables.SelectMany(t => t.Indexes)
    
    0 讨论(0)
  • 2021-02-18 17:14
    var rows = from item in table select item;
    
    0 讨论(0)
  • 2021-02-18 17:17

    In addition to tbischel's answer, the query expression version of what you're going for is below.

    var indexes = from TableInfo tab in _tables 
                  from index in tab.Indexes
                  select index;
    
    0 讨论(0)
  • 2021-02-18 17:21

    You don't need the where clause and you also shouldn't need to tell it what tab is

    And you will need to use SelectMany

    var indexes = (from tab in _tables).SelectMany(t => t.Indexes)
    

    Or you could do it like this

       var indexes = from tab in _tables
                      from t in tab.Indexes
                      select t;
    

    That should be a little more familiar syntaz

    0 讨论(0)
提交回复
热议问题