Permalink
Fetching contributors…
Cannot retrieve contributors at this time
80 lines (56 sloc) 3.01 KB
title ms.date ms.prod ms.technology ms.topic dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author translation.priority.ht
Arrays (C# Programming Guide)
2015-07-20
.net
devlang-csharp
article
CSharp
arrays [C#]
C# language, arrays
bb79bdde-e570-4c30-adb0-1dd5759ae041
33
BillWagner
wiwagn
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw

Arrays (C# Programming Guide)

You can store multiple variables of the same type in an array data structure. You declare an array by specifying the type of its elements.

type[] arrayName;

The following examples create single-dimensional, multidimensional, and jagged arrays:

[!code-cscsProgGuideArrays#1]

Array Overview

An array has the following properties:

  • An array can be Single-Dimensional, Multidimensional or Jagged.

  • The number of dimensions and the length of each dimension are established when the array instance is created. These values can't be changed during the lifetime of the instance.

  • The default values of numeric array elements are set to zero, and reference elements are set to null.

  • A jagged array is an array of arrays, and therefore its elements are reference types and are initialized to null.

  • Arrays are zero indexed: an array with n elements is indexed from 0 to n-1.

  • Array elements can be of any type, including an array type.

  • Array types are reference types derived from the abstract base type xref:System.Array. Since this type implements xref:System.Collections.IEnumerable and xref:System.Collections.Generic.IEnumerable%601, you can use foreach iteration on all arrays in C#.

Related Sections

C# Language Specification

[!INCLUDECSharplangspec]

See Also

C# Programming Guide
Collections
Array Collection Type