说我有
var i = 987654321;
var is = new int[] { 9,8,7,6,5,4,3,2,1 };
没有.ToString()并使用int.Parse(x)来迭代chars.
解决方法
public Stack<int> NumbersIn(int value) { if (value == 0) return new Stack<int>(); var numbers = NumbersIn(value / 10); numbers.Push(value % 10); return numbers; } var numbers = NumbersIn(987654321).ToArray();
替代无递归:
public int[] NumbersIn(int value) { var numbers = new Stack<int>(); for(; value > 0; value /= 10) numbers.Push(value % 10); return numbers.ToArray(); }