C
C#2y ago
smiley303

✅ Array Problem - the variable "i" here appears to never change?

int[] numbers = new int[5];

for (int i = 0;i < numbers.Length; i++)
{
Console.WriteLine($"Please enter a number to fill index: {numbers[i]}");
int userInput = Convert.ToInt32(Console.ReadLine());
numbers[i] = userInput;
}
int[] numbers = new int[5];

for (int i = 0;i < numbers.Length; i++)
{
Console.WriteLine($"Please enter a number to fill index: {numbers[i]}");
int userInput = Convert.ToInt32(Console.ReadLine());
numbers[i] = userInput;
}
I have a feeling it is this part "{numbers[i]}" but i don't understand why, the output is in image attached and also it stops after it accepts 5 variable which makes me think i is being incremented.
4 Replies
Angius
Angius2y ago
Well, yeah, an array of integers will be filled with zeroes numbers[i] will always be 0 Because the array contains only 0s
smiley303
smiley303OP2y ago
im retrieving the value when i want to retrieve the index of the array
phaseshift
phaseshift2y ago
Right.
smiley303
smiley303OP2y ago
makes sense
Want results from more Discord servers?
Add your server