Using linq to create more values?

I have an IEnumerable<int> that I can print, and which I can double (code below). It's not a problem. How to adjust the linq operator so that it accepts these 3 values ​​and outputs 6 values? For example, the values ​​are double and half, so the values ​​will be 12, 3, 16, 4, 8, 2 .

 foreach (var v in (new int[] { 6, 8, 4 }).Select(s=>s*2)) Console.WriteLine(v); 
+4
source share
1 answer

You need SelectMany :

 foreach (var v in (new[] { 6, 8, 4 }).SelectMany(s => new[] { s * 2, s / 2 })) Console.WriteLine(v); 
+8
source

Source: https://habr.com/ru/post/1496026/


All Articles