user18084277
user18084277

Reputation:

How to convert from string to char[] and then to long[]

Ok so my goal is to convert from string "1234567" to char array what I managed to achive(incredible) but now I am stuck and have no idea what I did wrong here...

static void Main(string[] args)
    {
        Console.WriteLine(Digitize(1234567));
    }
    public static long[] Digitize(long n)
    {
        string l = n.ToString();
        char[] p = l.ToCharArray();
        long[] nums = new long[p.Length];
        for (int i = 0; i < p.Length; i++)
        {
            nums[i] = long.Parse(p[i].ToString());
        }
        
        return nums;
    }

All I have in output is "System.Int64[]" (I would love to see some linq answers if that is possible)

Upvotes: 0

Views: 72

Answers (1)

Daniel
Daniel

Reputation: 9829

I think you did everything correctly.

Problem is your output.

Try:

static void Main(string[] args)
{
    long[]? result = Digitize(1234567);
    foreach (long number in result)
    {
        Console.WriteLine(number);
    }
}

Upvotes: 3

Related Questions