CHAPTER 15

image

Arrays

Arrays in C# are reference objects; they are allocated out of heap space rather than on the stack. The elements of an array are stored as dictated by the element type; if the element type is a reference type (such as string), the array will store references to strings. If the element type is a value type (such as a numeric type or a struct type), the elements are stored directly within the array.

Arrays are declared using the following syntax:

<type > [] identifier;

The initial value of an array is null. An array object is created using new.

int[] store = new int[50];string[] names = new string[50];

When an array is created, ...

Get A Programmer's Guide to C# 5.0, 4th Edition now with O’Reilly online learning.

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