Note that there are some explanatory texts on larger screens.

plurals
  1. POMerge multiple Lists into one List with LINQ
    primarykey
    data
    text
    <p>Is there a slick way to merge multiple Lists into a single List using LINQ to effectively replicate this?</p> <pre><code>public class RGB { public int Red { get; set; } public int Green { get; set; } public int Blue { get; set; } public RGB(int red, int green, int blue) { Red = red; Green = green; Blue = blue; } } public void myFunction() { List&lt;int&gt; red = new List&lt;int&gt; { 0x00, 0x03, 0x06, 0x08, 0x09 }; List&lt;int&gt; green = new List&lt;int&gt; { 0x00, 0x05, 0x06, 0x07, 0x0a }; List&lt;int&gt; blue = new List&lt;int&gt; { 0x00, 0x02, 0x03, 0x05, 0x09 }; List&lt;RGB&gt; colors = new List&lt;RGB&gt;(); colors.Add(new RGB(red[0], green[0], blue[0])); colors.Add(new RGB(red[1], green[1], blue[1])); colors.Add(new RGB(red[2], green[2], blue[2])); colors.Add(new RGB(red[3], green[3], blue[3])); colors.Add(new RGB(red[4], green[4], blue[4])); } </code></pre> <p>Or, since the lists arrive separately, its more effective to merge them sequentially like the following.</p> <pre><code>public class RGB { public int Red { get; set; } public int Green { get; set; } public int Blue { get; set; } public RGB(int red, int green, int blue) { Red = red; Green = green; Blue = blue; } } public void myFunction() { List&lt;int&gt; red = new List&lt;int&gt; { 0x00, 0x03, 0x06, 0x08, 0x09 }; List&lt;RGB&gt; colors = new List&lt;RGB&gt;(); colors.Add(new RGB(red[0], 0, 0)); colors.Add(new RGB(red[1], 0, 0)); colors.Add(new RGB(red[2], 0, 0)); colors.Add(new RGB(red[3], 0, 0)); colors.Add(new RGB(red[4], 0, 0)); List&lt;int&gt; green = new List&lt;int&gt; { 0x00, 0x05, 0x06, 0x07, 0x0a }; colors[0].Green = green[0]; colors[1].Green = green[1]; colors[2].Green = green[2]; colors[3].Green = green[3]; colors[4].Green = green[4]; List&lt;int&gt; blue = new List&lt;int&gt; { 0x00, 0x02, 0x03, 0x05, 0x09 }; colors[0].Blue = blue[0]; colors[1].Blue = blue[1]; colors[2].Blue = blue[2]; colors[3].Blue = blue[3]; colors[4].Blue = blue[4]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload