-
Book Overview & Buying
-
Table Of Contents
Fundamentals for Self-Taught Programmers
By :
So far, we have created variables that can only have one value, but what if there was a way to get multiple values from one variable? This can be done with arrays. Arrays are special types that can hold multiple values of the same type. The following figure shows how they are defined:
Figure 6.10 – Defining an array
Getting started with arrays is easier when you declare and initialize the number of items in the array, also known as the size. The size can only be a whole number. Follow along with the examples by creating a new console application and trying them out for yourself.
If you wanted to make an array of five integers, you would define it the following way:
int[] numberArray = new int[5];
Let’s try another way to make an array, but this time, we will initialize it with values:
string[] primaryColors = {"red", "yellow", "blue"};
In this example, we created...