title: How to get all possible combinations of strings from List<string[]>?
body: <p>I'm doing a tag-like string match function where function checks is string contains any of possible words while maintaining their order, at least per tag.
  I figured out it will be best to precreate list of possibilities and on check simply see if string contains each of required combinations</p>
  
  <p>Maybe code will make it more clear.</p>
  
  <pre><code>List&lt;List&lt;string[]&gt;&gt; tags;
  
  List&lt;string[]&gt; innerList;
  
  List&lt;List&lt;string&gt;&gt; combinationsList;
  
  public void Generate(string pattern)
  {
      // i will add whitespace removal later so it can be ", " instead of only ","
  
      foreach (string tag in pattern.Split(','))
      {
          innerList = new List&lt;string[]&gt;();
  
          foreach (var varyword in tag.Split(' '))
          {
              innerList.Add(varyword.Split('|'));
          }
      }
  
      // atm i lack code to generate combinations in form of List&lt;List&lt;string&gt;&gt; 
      // and drop them into 'combinationsList'
  }
  
  // the check function will look something like isMatch = :
  public bool IsMatch(string textToTest)
  {
      return combinationsList.All(tc =&gt; tc.Any(c =&gt; textToTest.Contains(c)));
  }
  </code></pre>
  
  <p>So for example pattern: </p>
  
  <p><strong>"old|young john|bob, have|posses dog|cat"</strong></p>
  
  <ul>
  <li>tags:
  <ul>
  <li>List_1:
  <ul>
  <li>{old, young}</li>
  <li>{john, bob}</li>
  </ul></li>
  <li>List_2
  <ul>
  <li>{have, posses}</li>
  <li>{dog, cat}</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>So combinationsList will have:</p>
  
  <ul>
  <li>combinationsList :
  <ul>
  <li>List_1
  <ul>
  <li>"old john"</li>
  <li>"old bob"</li>
  <li>"young john"</li>
  <li>"young bob"</li>
  </ul></li>
  <li>List_2
  <ul>
  <li>"have dog"</li>
  <li>"have cat"</li>
  <li>"posses dog"</li>
  <li>"posses cat"</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>So results will be:</p>
  
  <ul>
  <li>old bob have cat = true, contains List_1:"old bob" and List_2:"have cat"</li>
  <li>young john have car = false, contains List_1:"young john" but doesn't contain any of List_2 combinations</li>
  </ul>
  
  <p>I cannot figure out how to iterate collection to get those combinations and how to get the combination per iteration.
  Also i cannot mess up the order so old john will not be also generated as john old. </p>
  
  <p>Please note that any of "variant words" in pattern may have more than 2 variants like for example "dog|cat|mouse"</p>