Home > Mobile >  How to convert from string to char[] and then to long[]
How to convert from string to char[] and then to long[]

Time:03-20

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)

CodePudding user response:

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);
    }
}
  •  Tags:  
  • c#
  • Related