Create all word variations of 2 character arrays
I have 2 collections of caracter string ex:
List<string> one = new Li开发者_如何学运维st<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 variations of words that can be created from this. But i only want to create 4 character words! so for example i would want 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 getting to
czcz (from one[3],two[3],one[3],two[3])
Any suggestions on the fastest and best way to generate this
I doubt this solution will win any speed awards, but it should be reasonably quick:
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();
精彩评论