...
Example | Result | |||||
---|---|---|---|---|---|---|
| The array has been created with a fixed number of items We use a for loop to iterate across the items in the array. Each array has a Length property that can be used to determine the size of the array. Accessing items within the array is done through the index operator []. Arrays are zero indexed. The value used in within the index operator must >= 0 and <= array size -1 | |||||
| The array is created with a fixed size but the items are all empty strings Populating each entry in the array Use the for loop to access the items in the array. | |||||
| The foreach keyword In this example, the array is created with a fixed number of items. In the foreach satement, each item in numbers is projected one by one into the number variable. Each time a value from numbers is projected into the number the code block is executed with the current value in number. This repeats until all items within numbers have been exhausted. |