This question already has answers here:
Is there an easy way to turn an int into an array of ints of each digit?
(9个答案)
5年前关闭。
说我有12345。
我想要每个数字的单独物品。一个字符串会做,甚至是一个单独的数字。
.Split方法对此是否有重载?
(9个答案)
5年前关闭。
说我有12345。
我想要每个数字的单独物品。一个字符串会做,甚至是一个单独的数字。
.Split方法对此是否有重载?
最佳答案
我会使用模数和循环。
int[] GetIntArray(int num)
{
List<int> listOfInts = new List<int>();
while(num > 0)
{
listOfInts.Add(num % 10);
num = num / 10;
}
listOfInts.Reverse();
return listOfInts.ToArray();
}
关于c# - 如何在C#中将数字拆分为单个数字? [复制],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4808612/