<分区>
我想得到一个序列的整数从值A到值B。
例如 A=3
和 B=9
。现在我想用一行代码创建一个序列 3,4,5,6,7,8,9
并且没有循环。我试过 Enumerable.Range
,但没有找到有效的解决方案。
有人有想法吗?
<分区>
我想得到一个序列的整数从值A到值B。
例如 A=3
和 B=9
。现在我想用一行代码创建一个序列 3,4,5,6,7,8,9
并且没有循环。我试过 Enumerable.Range
,但没有找到有效的解决方案。
有人有想法吗?
最佳答案
var sequence = Enumerable.Range(min, max - min + 1);
?
不过,对于信息 - 就我个人而言,我仍然很想使用循环:
for(int i = min; i <= max ; i++) { // note inclusive of both min and max
// good old-fashioned honest loops; they still work! who knew!
}
关于C#:从最小值到最大值的序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16985142/