O'Reilly logo

C# Primer: A Practical Approach by Stanley B. Lippman

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

1.10. The C# Array

The built-in array in C# is a fixed-size container holding elements of a single type. When we declare an array object, however, the actual size of the array is not part of its declaration. In fact, providing an explicit size generates a compile-time error—for example,

string []     text; // OK
string [ 10 ] text; // error

We declare a multidimensional array by marking each additional dimension with a comma, as follows:

string [,]    two_dimensions;
string [,,]   three_dimensions;
string [,,,]  four_dimensions;

When we write

string [] messages;

messages represents a handle to an array object of string elements, but it is not itself the array object. By default, messages is set to null. Before we can store elements within the array, ...

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