13,143,774 members (31,286 online)
Rate this:
See more:
Hello.
Is there any fast and good method to combine all strings in x-list in any possible way?
I have List<List<string>>, which looks like:
0: A
B
C

1: 1
2
3

2: X
Y
Z

And my output should be like:
A1X, A1Y, A1Z, A2X, A2Y, A2Z, A3X, A3Y, A3Z, B1X, B2Y etc.

Any idea how can i do that?

Fixed HTML on the datatype - OriginalGriff[/edit]
Posted 5-Dec-12 22:26pm
Updated 5-Dec-12 22:35pm
v2

Rate this:

## Solution 2

1. using linq
http://www.functionx.com/csharp/linq/Lesson11.htm[^]

2. using sql
```select distinct list1.a + list2.a + list3.a as Combination from
(   select 'a' as a union all   select 'b' as a union all   select 'c' as a) as list1
cross join
(   select '1' as a union all   select '2' as a union all   select '3' as a ) as list2
cross join
(   select 'x' as a union all   select 'y' as a union all   select 'z' as a) as list3```

3. Many For loops

Happy Coding!
:)
Rate this:

## Solution 1

Hello Trucha ji
You can use LINQ CONCAT & TOLIST

var allProducts = productCollection1.Concat(productCollection2)
.Concat(productCollection3)
.ToList();Note that there are more efficient ways to do this - the above will basically loop through all the entries, creating a dynamically sized buffer. As you can predict the size to start with, you don't need this dynamic sizing... so you could use:

var allProducts = new List<product>(productCollection1.Count +
productCollection2.Count +
productCollection3.Count);

Top Experts
Last 24hrsThis month
 OriginalGriff 358 Dave Kreskowiak 170 Richard MacCutchan 110 Richard Deeming 95 Jochen Arndt 95
 OriginalGriff 5,450 Graeme_Grant 5,053 ppolymorphe 1,834 Jochen Arndt 1,804 CPallini 1,560