How to split a number into individual nos

后端 未结 1 702
耶瑟儿~
耶瑟儿~ 2021-01-21 13:16

I have a int number = 1782901998 whose Length is 10 numbers; I need to split them into 10 different strings. I tried the following code, but it does not give back a

相关标签:
1条回答
  • 2021-01-21 14:07

    Because your code fills the array with the ASCII code for the characters of the number variable. You can use LINQ like below:

    int[] digits = number.Select(c => Convert.ToInt32(c.ToString())).ToArray();
    

    Or if you want to assign the each number to a string simply:

    string[] digits = number.Select(c => c.ToString()).ToArray();
    
    0 讨论(0)
提交回复
热议问题