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

Where did these numbers come from?

So I have a code here and what I am tring to do is to get max and min value from string("1 2 3 4 5 6 66") and when I tried to make a char array from this string and get from it max and min I am getting 54 as a max and 32 as a min. HOW?

    static void Main(string[] args)
    {
        HighAndLow("1 2 3 4 5 6 66");
    }
    public static string HighAndLow(string numbers)
    {
        char[] liczby = numbers.ToArray();

        int max = liczby.Max();
        int min = liczby.Min();
        
        Console.WriteLine($"{max} {min}");
        return $"{max} {min}";

    }

>Solution :

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

You’re getting the char codes, not the values.

Change

 char[] liczby = numbers.ToArray();

to something like

char[] temp = numbers.Split(' ');
int[] liczby = temp.Select(c => int.parse(c)).ToArray();
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