I have a list with some values, lets say 1 2 3 4 5 6
I need to pair them up like this: 12 13 14 15 16 23 24 25 26 34 35 36 45 46 56
Basically, I need to mix them all up to create unique sets of values.
Do you have any ideas on how to create a new list like this?
Thank you for your input!
Using Linq and tuples:
var arr = new[] { 1, 2, 3, 4, 5, 6 };
arr.SelectMany((fst, i) => arr.Skip(i + 1).Select(snd => (fst, snd)));
If you like Linq:
var ar = new int[] {1, 2, 3, 4, 5};
var combo = (from left in ar
from right in ar where right > left
select new { left, right }).ToArray();
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