Create all word variants from 2 character arrays

I have 2 sets of caracter ex lines:

List<string> one = new List<string>;
one.Add("a");
one.Add("b");
one.Add("c");

List<string> two = new List<string>;
two.Add("x");
two.Add("y");
two.Add("z");

      

What I would like to do is create a list of all the word variations that can be generated from this. But I only want to create 4 character words! so, for example, I would like words like

axax (from one[1],two[1],one[1],two[1])
ayax (from one[1],two[2],one[1],two[1])
azax (from one[1],two[3],one[1],two[1])

      

eventually get to

czcz (from one[3],two[3],one[3],two[3])

      

Any suggestions for the fastest and most efficient way to create this

+2


a source to share


1 answer


I doubt this solution will win any speed awards, but it should be fast enough:



var one = new [] { "a", "b", "c" };
var two = new [] { "x", "y", "z" };

var ot = from o in one from t in two select o + t;
var r = from f in ot from s in ot select f + s;
var list = r.ToList();

      

+5


a source







All Articles