trying to iterate with this for loop and input int from user into array. I am getting an error and don’t understand why..
error: Error 1 Use of unassigned local variable ‘array’
using System;
namespace Lab16
{
class Program
{
static void Main(string[] args)
{
int[] array;
int value;
Console.Write("How big of an Array? ");
int arraySize = int.Parse(Console.ReadLine());
for (int i = 0; i <= arraySize; i++)
{
Console.Write("First Value: ");
value = int.Parse(Console.ReadLine());
--> array[i] = Convert.ToInt32(value);
}
}
}
}
Your array variable isn’t initialized. Writing this should fix it:
(Note, of course this needs to go after you’ve read arraySize from the console…)
And one more problem … your for loop as written is going to go out of bounds. Should be like this: