I have several lists of such lines, from a possible list of several tens:
1: { "A", "B", "C" } 2: { "1", "2", "3" } 3: { "D", "E", "F" }
These three were selected only as an example, and the user can choose from several dozen similar lists with a different number of elements. For another example, this is also a perfectly valid choice for the user:
25: { } // empty 4: { "%", "!", "$", "@" } 16: { "I", "a", "b", "Y" } 8: { ")", "z", "!", "8" }
I want to make every possible combination of strings, keeping the "order" of the lists. In other words, if we look at the first list, the first combination will be A1D , then A1E , then A1F , then B1D , then B1E , etc. Etc. So far I have written this recursive algorithm:
public void Tester() { var 2dList = new List { list1, list2, list3 }; var answer = ReturnString(2dList).ToList(); answer.ForEach(Console.WriteLine); } public IEnumerable<string> ReturnString(List<List<string>> list) { if (!list.Any()) { yield return null; } else {
However, I get this in return:
AStringGeneration.StringGenerator+<ReturnString>d__11 BStringGeneration.StringGenerator+<ReturnString>d__11 CStringGeneration.StringGenerator+<ReturnString>d__11
StringGeneration is the name of the class in which ReturnString is located. When I put a breakpoint on the yield return letter + ... , it seems to go through A , B and C , but not really recursively. I'm not sure what is going on here. Can someone explain what is wrong with my algorithm?