// 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 ix) { if(ix < len) { for(int i = 0; i < elms.Length; i++) { Combine(elms, len, p, comb + elms[i], ix + 1); } } else { p(comb); } } public static void Combine(string[] elms, int len, Process p) { Combine(elms, len, p, "", 0); } public static void Main(string[] args) { Combiner.Combine(new string[] { "A", "B", "C" }, 2, delegate(string comb) { Console.WriteLine(comb); }); } } }