C# Language Arrays

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9


  • Declaring an array:

    <type>[] <name>;

  • Declaring two-dimensional array:

    <type>[,] <name> = new <type>[<value>, <value>];

  • Declaring a Jagged Array:

    <type>[] <name> = new <type>[<value>];

  • Declaring a subarray for a Jagged Array:

    <name>[<value>] = new <type>[<value>];

  • Initializing an array without values:

    <name> = new <type>[<length>];

  • Initializing an array with values:

    <name> = new <type>[] {<value>, <value>, <value>, ...};

  • Initializing a two-dimensional array with values:

    <name> = new <type>[,] { {<value>, <value>}, {<value>, <value>}, ...};

  • Accessing an element at index i:


  • Getting the array's length:



In C#, an array is a reference type, which means it is nullable.

An array has a fixed length, which means you cant .Add() to it or .Remove() from it. In order to use these, you would need a dynamic array - List or ArrayList.

Got any C# Language Question?