using System; using System.Linq; using System.Collections.Generic; public class Test { static void CollectAll(ISet remaining, IList soFar, List> all) { if (soFar.Count != 0) { all.Add(soFar.ToList()); } foreach (var item in remaining.ToList()) { remaining.Remove(item); soFar.Add(item); CollectAll(remaining, soFar, all); soFar.Remove(item); remaining.Add(item); } } public static void Main() { var items = new HashSet {"a", "b", "c"}; var tmp = new List(); List> res = new List>(); CollectAll(items, tmp, res); foreach (var lst in res) { Console.WriteLine(string.Join(" ", lst.ToArray())); } } }