Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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);
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading