December 2001
Intermediate to advanced
416 pages
8h 16m
English
We use the new expression to allocate either a single object:
Hello myProg = new Hello(); // () are necessary
or an array of objects:
messages = new string[ 4 ];
on the program's managed heap.
The name of a type follows the keyword new, which is followed by either a pair of parentheses (to indicate a single object) or a pair of brackets (to indicate an array object). We look at the allocation of a single reference object in Section 2.7 in the discussion of class constructors. For the rest of this section, we focus on the allocation of an array.
Unless we specify an initial value for each array element, each element of the array object is initialized to its default value. (The default value for numeric types is 0
Read now
Unlock full access