Vinod Dua
How to declares a two-dimensional array in C#?
Posted by Vinod Dua in C# Language on Jun 08, 2012
  • 1
  • 5
  • 3387
Do you know the answer for this question? Post it below.
Guest
Posted by Keyur Patel on Apr 16, 2013
  • 0

string[,] strArray= new string[3,3];

You can also instantiate it in the same line with array initializer syntax as follows:

string[,] strArray = new string[3, 3] {{"a","b","c"},
{"d","e","f"},
{"g","h","i"} };

For more about the Multidimension array. You can refer following Link.
http://msdn.microsoft.com/en-us/library/2yd9wwz4(v=vs.71).aspx

Posted by Keyur Patel on Apr 16, 2013
  • 0

string[,] strArray= new string[3,3];

You can also instantiate it in the same line with array initializer syntax as follows:

string[,] strArray = new string[3, 3] {{"a","b","c"},
{"d","e","f"},
{"g","h","i"} };

For more information about the Multidimensional Arrays

Posted by Akshay Patel on Sep 02, 2012
  • 0

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

Posted by Akshay Patel on Sep 02, 2012
  • 0

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

Posted by Mandar Desai on Jul 05, 2012
  • 0

Two Dimensional Array:



These are arrays which represent data in the forms of rows and columns.



Int [,]=new int[3,4];

Or

Int[,] arr;

Arr=new int[2,3];



We can identify each and every cell by using row and column index as following:



Int [,] arr=new int[4,5];

Arr[0,0]=5;

Arr[0,1]=10;



We can use getlength method to find no. of rows and column as following:



Arr.getlength(0) for Rows

Arr.getlength(1) for columns

Class tdarray

{

Static void main()

{

Int a=5;

Int[,] arr=new int[4,5];

For( int i=0;i
{

For(int j=0;j
{

Arr[I,j]=a;

a+=5;

}}

//printing

For( int i=0;i
{

For(int j=0;j
Console.write(arr[I,j] + "");

Console.writeline();

}

}

}



Assigning values to a 2D array at the time of declaration:



Int[,] arr= { {11,12,13,14},

{21,22,23,24},

{31,32,33,34},

{41,42,43,44},

};


Most Popular Companies

Most Popular Job Functions

MOST LIKED QUESTIONS

PRIVACY POLICY | TERMS & CONDITIONS | SITEMAP | CONTACT US | ABOUT US | REPORT ABUSE
2014© C# Corner. All contents are copyright of their authors.