I want the user to enter a group of int
s, then the program finds the maximum value.
The problem that it crashes every time I run it.
This is my code:
public int maximum()
{
int arrSize = 0;
int [] list = new int [arrSize];
Console.Write("how many numbers u want to find the max between them : ");
arrSize = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nplz enter the list of numbers : ");
for (int j = 0; j < arrSize; j++)
list[j] = int.Parse(Console.ReadLine());
int max = list[0];
for (int i = 1; i < arrSize;i++ )
if (list[i] > max) max = list[i];
return max;
}
I already tried with Convert.ToInt16
, so what should I do?