Find minimum and maximum number from array, minimum is always 0

后端 未结 5 1704
春和景丽
春和景丽 2021-01-12 06:26

The program first asks the user for the number of elements to be stored in the array, then asks for the numbers.

This is my code

    static void Main         


        
5条回答
  •  梦毁少年i
    2021-01-12 06:56

    Besides on your problem, you can use Enumerable.Min and Enumerable.Max methods like;

    int[] numbers = new int[]{1, 2, 3 ,4};
    Console.WriteLine(numbers.Min()); //1
    Console.WriteLine(numbers.Max()); //4
    

    Don't forget to add System.Linq namespace.

提交回复
热议问题