I’m not completely sure that the term ‘Combination’ is correct, however I have a requirement to build a list of combination form one or more List. Each list will contain a varying number of elements, e.g.
List<string> lBag1 = ["1_0, 1_1, 1_3"]
List<string> lBag2 = ["11_0, 11_1, 11_8"]
List<string> lBag3 = ["3_0"]
What I need is all combination of the Lists form 1 to n elements with no more than one element from each list, e.g.
"1_0"
"1_1"
"1_3"
"11_0"
"11_1"
"11_8"
"3_0"
"1_0 11_0"
"1_0 11_1"
"1_0 11_8"
"1_0 3_0"
...
"1_3 11_8 3_0"
Order is not important, so “1_0 11_0” is considered the same as “11_0 1_0”.
Any assistance would be greatly appreciated
These two extension methods will let you chain together several enumerations, calculating the combinations you want.
Each combination is an enumeration, rather than a concatenated string.
Alternatively, there is this classic Eric Lippert blog post that does a similar thing. (Similar result, very different method.)