Im making a code that gets the user input and put then in descending order, but i need help in this part, to put the user input into a array, the much input the user make, only stopping when '-1' is typed. Here is the code:
int []vet = new int[]{};
for(int i = 0; i != -1;i++)
{
Console.WriteLine("digite os valores");
int input = int.Parse(Console.ReadLine());
vet[i] = input;
}
This code generates this error: "Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array."
List<int>instead to store user's input so that you won't have to worry about the index anymore. Plus, you declare an array of 0 length that is why you get this error. And your FOR loop is an infinite one causei != -1will always be true and you'll never reach-1. You should avoid doing that.