```/// /// Compute the set of combinations, where a combination is an un-ordered collection /// of elements taken from the candidate set. Each element must appear zero or once. /// For set [1,2,3], the combinations are , [1,2], [1,2,3], , [2,3] and . /// /// The type of objects whose combinations we evaluate /// The set from which to combine elements /// The set of combinations public static IEnumerable> Combinations(this IEnumerable set) { int n = set.Count();   for (int skip = 0; skip < n; skip++) { for (int take = 1; take <= n - skip; take++) { yield return set.Skip(skip).Take(take); } } }```
 ```[TestMethod] public void CombinationsOfNone() { var candidates = new List(); var combinations = new List>();   AssertEqualSetsOfSets(combinations, candidates.Combinations()); }   [TestMethod] public void CombinationsOfOne() { var candidates = new List() { 1 };   var combinations = new List>() { new List() {1} };   AssertEqualSetsOfSets(combinations, candidates.Combinations()); }   [TestMethod] public void CombinationsOfThree() { var candidates = new List() { 1, 2, 3 };   var combinations = new List>() { new List() {1}, new List() {1, 2}, new List() {1, 2, 3}, new List() {2}, new List() {2, 3}, new List() {3} };   AssertEqualSetsOfSets(combinations, candidates.Combinations()); }   private void AssertEqualSetsOfSets(List> expected, IEnumerable> actual) { Assert.AreEqual(expected.Count, actual.Count());   var expectedIter = expected.GetEnumerator(); var actualIter = actual.GetEnumerator();   while (expectedIter.MoveNext() && actualIter.MoveNext()) { Assert.IsTrue(OrderIndependentEqual(expectedIter.Current, actualIter.Current)); } }   public bool OrderIndependentEqual(IEnumerable first, IEnumerable second) { return !first.Except(second).Concat(second.Except(first)).Any(); }```