System.Array Is a Reference Type

The System.Array class is a reference type like System.String. Consequently an array variable containing a reference is separate from the array object it is referencing. A reference type variable can be assigned different references, just as a variable of a numeric type can be assigned different numbers. So an array variable can reference different array objects at different segments in a program by assigning different references to it. Recall the state of affairs after the following statement

decimal [] accountBalances = new  decimal[5];

as illustrated earlier in Figure 10.2. The accountBalances variable is referencing an array object of base type decimal and length 5. Suppose that later in the program you want ...

Get C# Primer Plus now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.