I have a string of numbers, like "31654918562314", and I want to convert it into an array of integers. The code I've written is:
string source = "31654918562314";
int[] numbers = new int[source.Length];
for (int i = 0; i < source.Length; i++)
{
numbers[i] = Convert.ToInt32(source.Substring(i, 1));
}
What improvements can I apply on this code? Is it the best ultimate code I can get to?
Note: I'm using C#. However, I also should implement this code in JavaScript.
0
from each digit, rather than callConvert.ToInt32()
orInt32.Parse()
. \$\endgroup\$Char.GetNumericValue
msdn.microsoft.com/en-us/library/e7k33ktz.aspx \$\endgroup\$