How to split a number into individual digits in c#?

c#, string

Solution

I'd use modulus and a loop.

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();
}

Problem

Say I have 12345. I'd like individual items for each number. A String would do or even an individual number. Does the .Split method have an overload for this?

Original source

Related problems