生成具有两个变量之间的每种组合的列表 [英] Generate List with Every Combination between two variables
本文介绍了生成具有两个变量之间的每种组合的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何自动生成List<string>
和A100B100
之间的每个组合的List<string>
?
How can I auto generate a List<string>
with every combination between A00B00
to A100B100
?
我想应该是10,100件.
I think it would be 10,100 items.
因此列表将包含:
A00B00
A00B01
A00B02
...
A01B00
A01B01
A01B02
...
A100B98
A100B99
A100B100
它需要保留AxxBxx
格式.我不希望它像0A01B0
那样混乱.
It needs to keep the AxxBxx
format. I do not want it to be scrambled like 0A01B0
.
推荐答案
此类组合称为笛卡尔积,这是另一个LINQ解决方案:
Such combinations are called Cartesian products, here's another LINQ solution:
var lst = Enumerable.Range(0, 101)
.SelectMany(a => Enumerable.Range(0, 101).Select(b => $"A{a:00}B{b:00}"))
.ToList();
这篇关于生成具有两个变量之间的每种组合的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文