I'm just asking for some basic C# help. I've just started working with arrays and I'm have trouble wrapping my brain around the logic. For a simple example, this console application takes 10 numbers from the user, stores them in an array with a score of 10, and then prints the sum of those numbers. I'll comment on what I do get (please correct me if I'm wrong), and where I get stopped up.
int arr = new int;
// initialize new array and assign it a score of 10
int sum = 0;
//declare sum and make it 0
for (int i = 0; i < 10; i++)
// creates a for loop, declares i and makes it 0, continues the loop until i is greater than 10, increments i after body
// asks the user for numbers
arr[i] = Convert.ToInt32(Console.ReadLine());
//takes the numbers, converts them to int, assigns them to arr[i]
sum = sum + arr[i];
// adds the value of sum(0 to start) to the value entered from the user, assigns that to sum
So basically, if "i" is declared in the for loop, and then used as a value for the array, how does "i" stay under 10 to continue the loop? If the user enters 30, that is assigned to the "i" value of arr. As each value is assigned to the "i" value of arr, does it then assign them in sequence to the index scores? 0,1,2,etc automatically?
I hope I'm not talking nonsense here, it always seems way overcomplicated. Basically I'm having trouble understanding how the values are assigned to the array, how the program knows to assign them without index scores given, and how it stays on track with adding the "i" value of arr to the sum, when the "i" value of arr should contain the full set of array numbers right? How is the value "i" in the for loop statements separated from the value of "i" used to assign numbers to the array? Phew.