Arrays are data structures consisting of related data items of the same type. They are fixedlength entities (remaining the same length once they’re created), although an array variable may be reassigned so that it refers to a new array of a different length.
We’ll discuss how to declare, create and initialize arrays, then show several examples of common array manipulations. We’ll present the foreach iteration statement, which provides a concise notation for accessing data in arrays.
You’ll use keyword var to declare implicitly typed local variables—as you’ll see, the compiler can determine a local variable’s type, based on its initializer value. We’ll introduce exception handling for detecting and processing problems that occur at execution time.
Many of the chapter’s examples manipulate arrays of int simple-type values. To demonstrate that arrays also can store reference types, we’ll create a card-shuffling-anddealing simulation that manipulates an array of Card objects. In that example, we’ll introduce C#’s getter-only auto-implemented properties, which define properties that can be used to get, but not set, a value.
We present two versions of an instructor GradeBook case study that use arrays to maintain sets of student grades in memory and analyze them. We’ll also demonstrate how to define methods that receive variable-length argument lists and a version of method Main that can receive a string array containing an app’s so-called command-line arguments.