12,404,251 members (73,618 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(productCollection1.Count +
productCollection2.Count +
productCollection3.Count);

Top Experts
Last 24hrsThis month
 OriginalGriff 278 Karthik Bangalore 240 Richard MacCutchan 227 Suvendu Shekhar Giri 225 ppolymorphe 170
 OriginalGriff 7,386 ppolymorphe 3,175 Karthik Bangalore 3,127 Richard MacCutchan 2,372 F-ES Sitecore 2,262