This is easy in a foreach loop - but I have several lists...
Example:
var ListA = new List<string>() { "One", "Two" };
var ListB = new List<string>() { "Three", "Four" };
var ListC = new List<string>() { "Five", "Six" };
var ListD = new List<string>() { "Seven", "Eight" };
My outcome would look like this:
One, Three, Five, Seven
One, Three, Five, Eight
One, Three, Six, Seven
One, Three, Six, Eight
One, Four, Five, Seven
One, Four, Five, Eight
One, Four, Six, Seven
One, Four, Six, Eight
And so on.
This works, but strikes me that there should be a better way of doing this.
foreach (var item in ListA)
{
foreach (var item2 in ListB)
{
foreach (var item3 in ListC)
{
foreach (var item4 in ListD)
{
outputCombined.Append(item.Trim() + " " + ";" + " " + item2.Trim() + " " + ";" + " " + item3.Trim() + " " + ";" + " " + item4.Trim() + Environment.NewLine);
}
}
}
}
I figure there might be a Linq solution to the problem?