SiteMap  | About    

Multi Dimensional Array

An array allows to refer related values by the same name and to use a number, called an index or subscript, to tell them apart. Array elements can be of any type, including an array type. Array is the abstract base type of all array types.

  double[] values ;

An array that uses more than one index or subscript is called multidimensional. A dimension is a direction in which you can vary the specification of an array's elements. C# supports single-dimensional arrays, multidimensional arrays and array-of-arrays .

Some arrays have two dimensions, therefore, such an array uses two indexes. The following example declares a variable to hold a two-dimensional array of office counts, for buildings 0 through 40 and floors 0 through 5.

  byte[,] offices = new byte[41, 6];

The following C# program shows a simple example of how to insert values in a two dimensional array and retrieve the values from two dimensional array.

using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
	public partial class Form1 : Form
		public Form1()

		private void button1_Click(object sender, EventArgs e)
			int i = 0;
			int j = 0;
			string[,] strArr = new string[2, 3];

			strArr[0, 0] = "First";
			strArr[0, 1] = "Second";

			strArr[1, 0] = "Third";
			strArr[1, 1] = "Fourth";

			for (i = 0; i <= strArr.GetUpperBound(0); i++)
				for (j = 0; j <= strArr.GetUpperBound(0); j++)
					MessageBox.Show (strArr[i, j]);
} (C) 2018    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.