// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; namespace E { public class Combiner { public delegate void Process(string comb); private static void Combine(string[] elms, int len, Process p, string comb, int start, int ix) { if(ix < len) { for(int i = start; i < elms.Length; i++) { Combine(elms, len, p, comb + elms[i], i + 1, ix + 1); } } else { p(comb); } } public static void Combine(string[] elms, int len, Process p) { Combine(elms, len, p, "", 0, 0); } public static void Combine(string[] elms, Process p) { for(int i = 1; i <= elms.Length; i++) { Combine(elms, i, p); } } public static void Main(string[] args) { Combiner.Combine(new string[] { "a", "b", "c", "d", "e" }, delegate(string comb) { Console.WriteLine(comb); }); } } }