title: C# LINQ combinatorics: All Combinations of a Set without the Empty Set
body: <p>I have a set of strings, and I want to find all possible combinations of the strings and add them to a list. I want to end up with a list of a list of each combination of the strings, minus the empty set.</p>
  
  <p>I have created a solution that does this exactly with a nested for loop. However <strong>I want to do this more elegantly, preferably with LINQ</strong>, and I am not so proficient with it because I'm still pretty new to it.</p>
  
  <p>The solution should have 2^n - 1 lists of combinations where n is the cardinality of the original set. Here is a correct example of what I am looking for: </p>
  
  <pre><code>set = {a, b, c}
  
  completedListOfCombinations = 
  {
      {a},
      {b},
      {a, b},
      {c},
      {a, c},
      {b, c},
      {a, b, c}
  }
  </code></pre>
  
  <p>Here is my working, basic but ugly solution that I crafted with help from: <a href="https://stackoverflow.com/a/3319652/3371287">https://stackoverflow.com/a/3319652/3371287</a></p>
  
  <pre><code>List&lt;string&gt; myStrings =  new List&lt;string&gt; { "a", "b", "c" };
  
  var allCombos = new List&lt;List&lt;string&gt;&gt;();
  
  for (int i = 0; i &lt; myStrings.Count; i++)
  {
      int subsetCount = allCombos.Count;
      var m = new List&lt;string&gt;();
      m.Add(myStrings[i]);
      allCombos.Add(m);
  
      for (int j = 0; j &lt; subsetCount; j++)
      {
          string[] subset = new string[allCombos.ElementAt(j).Count + 1];
          allCombos[j].CopyTo(subset, 0);
          subset[subset.Length - 1] = myStrings[i];
          allCombos.Add(subset.ToList());
      }
  
  }
  </code></pre>
  
  <p>Can someone show me a more elegant solution for this? I have seen similar LINQ solutions that create Cartesian Pairs and lists with a threshold, but I have not been able to tweak them to what I need.</p>