---
title: "what is an array in c#"  
description: "Let us talk about array in this article."  
author: "Ravi Vishwakarma"  
published: 2021-07-04  
canonical: https://www.mindstick.com/articles/327205/what-is-an-array-in-c-sharp  
category: "c#"  
tags: ["c#", ".net"]  
reading_time: 4 minutes  

---

# what is an array in c#

## What is [array in c#](https://answers.mindstick.com/qa/82421/what-is-array-in-c-sharp)

We can store multiple value in one variable but it’s treated as multiple variable. You can declare an array using square bracket “[ ]”. This bracket says that this is array. This is support the homogeneous type element in other words. An array can be single dimension, two dimension, and [jagged array](https://www.mindstick.com/blog/11595/jagged-arrays-in-c-sharp). The [default value](https://www.mindstick.com/forum/157761/how-to-add-a-column-with-a-default-value-to-an-existing-table-in-sql-server) of array is zero and object set to null. An array start with zero index, [mean if](https://answers.mindstick.com/qa/96063/on-reddit-what-does-it-mean-if-a-post-is-removed-by-moderators-when-i-can-still-view-access-comment-upvote-etc) array size have 5 then indexing start to zero “0” and end with 4. An array can be any type like int, float, string, [object type](https://www.mindstick.com/blog/398/difference-between-object-type-and-var-type).

## Types of array

1. Single dimension array
2. Multi dimensional array
3. Jagged array

## Single dimension array

We create the single dimension using “new” operator. This contain the elements array[0] to array[ array.size -1 ].

Array declaration-

Syntax .

Datatype-name[] name=new datatype[ size ];

Example –

int[] p=new int[6];

Array [initialization](https://www.mindstick.com/interview/608/what-is-the-difference-between-assignment-and-initialization)

Int[] number=new int[] {1,2,3,4,5};

Int[] number={1,2,3,4,5};

Int[] number=new int[9];

Number[0]=1;

Number[1]=2;

Number[2]=3;

Number[3]=4;

.

.

Number[8]=9;

## Multidimensional dimension array

Array can have more than one dimension . for example two, three, for dimension.

## Two dimensional array syntax

int[,] array = new int[4, 2];

in this example 4 represent the row and 2 is represent to column.

int[,] array2D = new int[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };

int[,] array2Da = new int[4, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };

string[,] array2Db = new string[3, 2] { { 'one', 'two' }, { 'three', 'four' },

{ 'five', 'six' } };

## Three dimensional array syntax

int[,,] array1 = new int[4, 2, 3];

in this declaration show that, 4 represent to row of 3rd dimensional array of 2X3 two dimensional.

int[,,] array3D = new int[,,] { { { 1, 2, 3 }, { 4, 5, 6 } },{ { 7, 8, 9 }, { 10, 11, 12 } } };

int[,,] array3Da = new int[2, 2, 3] { { { 1, 2, 3 }, { 4, 5, 6 } },{ { 7, 8, 9 }, { 10, 11, 12 } } };

## Jagged array

an array is an array whose elements are array. Other words “array of array” is called jagged array. This array flexible at runtime.

int[][] jaggedArray = new int[3][];

Before use of jagged array use must initialize the elements.

jaggedArray[0] = new int[5];

jaggedArray[1] = new int[4];

jaggedArray[2] = new int[2];

jaggedArray[0] = new int[] { 1, 3, 5, 7, 9 };

jaggedArray[1] = new int[] { 0, 2, 4, 6 };

jaggedArray[2] = new int[] { 11, 22 };

Other declaration

int[][] jaggedArray3 =

{

new int[] { 1, 3, 5, 7, 9 },

new int[] { 0, 2, 4, 6 },

new int[] { 11, 22 }

};

It is possible to mix the jagged and [multidimensional array](https://www.mindstick.com/forum/23344/multidimensional-array-of-nsinteger-as-instance-variable)

int[][,] jaggedArray4 = new int[3][,]

{

new int[,] { {1,3}, {5,7} },

new int[,] { {0,2}, {4,6}, {8,10} },

new int[,] { {11,22}, {99,88}, {0,9} }

};

class ArrayTest

{

[static void](https://www.mindstick.com/interview/2715/can-we-write-static-public-void-instead-of-public-static-void) Main()

{

// Declare the array of two elements.

int[][] arr = new int[2][];

// Initialize the elements.

arr[0] = new int[5] { 1, 3, 5, 7, 9 };

arr[1] = new int[4] { 2, 4, 6, 8 };

// Display the array elements.

for (int i = 0; i < arr.Length; i++)

{

System.Console.Write('Element({0}): ', i);

for (int j = 0; j < arr[i].Length; j++)

{

System.Console.Write('{0}{1}', arr[i][j], j == (arr[i].Length - 1) ? '' : ' ');

}

System.Console.WriteLine();

}

// Keep the console window open in [debug mode](https://www.mindstick.com/interview/23356/how-can-you-test-bundling-in-debug-mode).

System.Console.WriteLine('Press any key to exit.');

System.Console.ReadKey();

}

}

\

---

Original Source: https://www.mindstick.com/articles/327205/what-is-an-array-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
