O'Reilly logo

Beginning Object-Oriented Programming with C# by Jack Purdum

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 8

Understanding Arrays and Collections

What you will learn in this chapter:

  • Arrays
  • Array indexes and elements
  • How to set the size of an array
  • Some of the array class methods commonly used
  • Multidimensional arrays
  • Array lists
  • Collections
  • Jagged arrays

wrox.com code downloads for this chapter

You can find the wrox.com code downloads for this chapter at www.wrox.com/remtitle.cgi?isbn=9781118336922 on the Download Code tab. The code in the Chapter08 folder is individually named according to the names throughout the chapter.

In this chapter you learn about arrays, array lists, and collections. These data structures are useful to solve many types of programming problems. When you finish this chapter, you'll have an appreciation of how arrays can make certain programming problems much easier to solve.

What Is an Array?

An array is a group of identical data types that share a common name. The syntax to define an array is as follows:

typeSpecifier[] arrayName = new typeSpecifier[numberOfElements];

where:

  • typeSpecifier is the data type you want to use.
  • arrayName is the name you want to use for the array.
  • numberOfElements is the number of array elements you want.

Each of these parts is explained in a moment using the following example.

Suppose you have an address book with 100 names in it. Because you want to manipulate those names in some way in your program, each unique name must be stored in a unique variable. Because names are textual data, you could use something like this: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required