List of lind the flat setting of the linq display
Your Linq query returns a nested integer list, you want to display it as a single list. Given a list of source lists, you plan to merge all internal lists into a single, coherent list.
Solution:
Use the selectmany () method in Linq to complete this task. Selectmany () is good at flattening nested collection and converts it into a single element sequence.
The following is the method you can use selectmany ():
In this example, iList represents your initial setting integer list. By using selectmany () and a lambda expression (map each internal list to itself (i = & gt; i)), you can effectively connect the elements in all internal lists into a single sequence. The generated result variable contains the list after the display.
<code class="language-csharp">var result = iList.SelectMany(i => i);</code>
Consider the source array: [1, 2, 3, 4] and [5, 6, 7]. After using SelectMany (), you will get the single array you need: [1, 2, 3, 4, 5, 5, 6, 7].
The above is the detailed content of How Can I Flatten a Nested List of Integers in LINQ?. For more information, please follow other related articles on the PHP Chinese website!