我有两个caracter字符串集合 例如:
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");
我想要做的是创建一个可以从中创建的所有单词变体的列表。 但我只想创造4个字符的单词! 所以例如我想要像
这样的词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])
最终到达
czcz (from one[3],two[3],one[3],two[3])
有关生成此
的最快和最佳方式的任何建议答案 0 :(得分:5)
我怀疑这个解决方案会赢得任何速度奖励,但它应该相当快:
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();