In this chapter from Microsoft® Visual C#® 2013 Step by Step, you will learn to declare, create, populate and use an array, access and individual array element, iterate through an array.
After completing this chapter, you will be able to:
Declaring and creating an array
Populating and using an array
Accessing an individual array element
Iterating through an array
You have already seen how to create and use variables of many different types. However, all the examples of variables you have seen so far have one thing in common—they hold information about a single item (an int, a float, a Circle, a Date, and so on). What happens if you need to manipulate a set of items? One solution is to create a variable for each item in the set, but this leads to a number of further questions: How many variables do you need? How should you name them? If you need to perform the same operation on each item in the set (such as increment each variable in a set of integers), how would you avoid very repetitive code? This solution assumes that you know, when you write the program, how many items you will need, but how often is this the case? For example, if you are writing an application that reads and processes records from a database, how many records are in the database, and how likely is this number to change?
Arrays provide a mechanism that helps to solve these problems.
Read the rest of the chapter here: https://www.microsoftpressstore.com/articles/article.aspx?p=2199429.
Interested in more free sample chapters? Check out our growing collection here: https://www.microsoftpressstore.com/articles/.