Locked lesson.
About this lesson
In this lesson, we learn how to create and access Arrays.
Exercise files
Download this lesson’s related exercise files.
23 - Creating and Accessing Arrays.docx61.1 KB 23 - Creating and Accessing Arrays SOLUTION.docx
58 KB
Quick reference
Creating and Accessing Arrays
An array is like a variable that you can put more than one thing in.
When to use
Use them when you need to deal with more than one item.
Instructions
string[] names = new string[3];
names[0] = "John";
names[1] = "Mary";
names[2] = "Tim";
Console.WriteLine(names[0]); // outputs John
// Another way to add things to an array:
string[] names = new string[3] {"John", "Mary", "Tim"};
Hints & tips
- string[] names = new string[3];
- string[] names = new string[3] {"John", "Mary", "Tim"};
- names.Length // returns length of the 'names' array
Lesson notes are only available for subscribers.