C# GUI application that stores an array and displays the highest and lowest numbers by clicking a button

后端 未结 2 1119
故里飘歌
故里飘歌 2021-01-29 08:43

Background:
This is updated from 13 hours ago as I have been researching and experimenting with this for a few. I\'m new to this programming arena so I\'ll b

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-29 08:56

    This looks like homework, so you should try a bit more than that. Here is what you could do: parse the string (say it's a comma-separated list of numbers), cast each value to int and populate your array. You can either call .Max() / .Min() methods or loop through the values of the array and get the max / min value. Here is a bit of code:

    int n = 10;
    int[] numbers = (from sn in System.Text.RegularExpressions.Regex.Split(inputText.Text, @"\s*,\s*") select int.Parse(sn)).ToArray();
    int max = numbers.Max();
    int min = numbers.Min();
    //int max = numbers[0];
    //int min = numbers[0];
    //for(int i = 1; i < n; i++)
    //{
    //    if(max < numbers[i])
    //    {
    //        max = numbers[i];
    //    }
    //    if(min > numbers[i])
    //    {
    //        min = numbers[i];
    //    }
    //}
    

提交回复
热议问题