I want to let the user define the size of the array and all of the numbers inside it, so this is what I had in mind:
int []arr={0};
Console.WriteLine("Please enter the size of the array:");
size = Console.Read();
for(int i=0; i<size; i++)
{
Console.WriteLine("Please enter the next number in the array, it's position is: " + i);
arr[i] = Console.Read();
}
When I try to run it gives me an 'index out of range' error. If someone could point what am I doing wrong I would really appreciate it.
EDIT: After the answer I changed the code a little bit and now it looks like this:
Console.WriteLine("Please enter the size of the array:");
input = Console.ReadLine();
size = int.Parse(input);
int[] arr = new int[size];
for(int i=0; i<size; i++)
{
string b;
Console.WriteLine("Please enter the next number in the array, it's position is: " + i);
b = Console.ReadLine();
arr[i] = int.Parse(b);
}
So now the array can be bigger and so does the numbers inside, thanks again for the help!