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}";
}
CodePudding user response:
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();
CodePudding user response:
Look here
You will see that the character 'c' is decimal 54
and that " " (space) has decimal value 32