Flatten List in LINQ

前端 未结 5 1807
独厮守ぢ
独厮守ぢ 2020-11-22 08:47

I have a LINQ query which returns IEnumerable> but i want to return only List so i want to merge all my record in

相关标签:
5条回答
  • 2020-11-22 09:06

    If you have a List<List<int>> k you can do

    List<int> flatList= k.SelectMany( v => v).ToList();
    
    0 讨论(0)
  • 2020-11-22 09:07

    Try SelectMany()

    var result = iList.SelectMany( i => i );
    
    0 讨论(0)
  • 2020-11-22 09:12

    Like this?

    var iList = Method().SelectMany(n => n);
    
    0 讨论(0)
  • 2020-11-22 09:15
    iList.SelectMany(x => x).ToArray()
    
    0 讨论(0)
  • 2020-11-22 09:32

    With query syntax:

    var values =
    from inner in outer
    from value in inner
    select value;
    
    0 讨论(0)
提交回复
热议问题