using System.Collections.Generic;
static List<List<string>> input = new List<List<string>>()
new List<string>() {"a", "b", "c"},
new List<string>() {"d", "e"},
new List<string>() {null},
new List<string>() {"f", "g"},
public static void Main()
StringBuilder sb = new StringBuilder();
List<string> priorPerm = new List<string>();
foreach (List<string> curList in input)
foreach (string perm in priorPerm)
priorPerm = new List<string>();
else if (priorPerm.Count == 0)
priorPerm.AddRange(curList);
List<string> newPerm = new List<string>();
foreach (string perm in priorPerm)
foreach(string curStr in curList)
newPerm.Add(perm + " " + curStr);
foreach (string perm in priorPerm)
Console.WriteLine(sb.ToString());