Arrays

Arrays are reference type data structures that can contain a number of other variables. These variables, known as elements, are accessed via indexes. C# arrays start with a zero index.

In C# and other .NET languages, arrays are heap allocated, but the storage of each element is dictated by that element's type. In other words, if an array contains objects, the array contains references to those objects, but if the array contains integers, the array actually contains those integers.

Declaring Arrays

You declare arrays by specifying the type of array, brackets ([]), the name of the array variable, and a size. The new operator creates the array and initializes its elements to their default value:

String [] sNonsense = new String[4];

Initializing ...

Get Building e-Commerce Sites with the .NET Framework now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.