I have a LINQ query which returns IEnumerable<List<int>>
but i want to return only List<int>
so i want to merge all my record in my IEnumerable<List<int>>
to only one array.
Example :
IEnumerable<List<int>> iList = from number in (from no in Method() select no) select number;
I want to take all my result IEnumerable<List<int>>
to only one List<int>
Hence, from source arrays: [1,2,3,4]
and [5,6,7]
I want only one array [1,2,3,4,5,6,7]
Thanks
Select and SelectMany are projection operators. A select operator is used to select value from a collection and SelectMany operator is used to selecting values from a collection of collection i.e. nested collection.
SelectMany(<selector>) method For example, SelectMany() can turn a two-dimensional array into a single sequence of values, as shown in this example: int[][] arrays = { new[] {1, 2, 3}, new[] {4}, new[] {5, 6, 7, 8}, new[] {12, 14} }; // Will return { 1, 2, 3, 4, 5, 6, 7, 8, 12, 14 } IEnumerable<int> result = arrays.
Try SelectMany()
var result = iList.SelectMany( i => i );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With