
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Define a Rectangular Array in C#
Multi-dimensional arrays are also called rectangular array. You can define a 3-dimensional array of integer as −
int [ , , ] a;
Let us see how to define a two-dimensional array −
Int[,] a = new[3,3]
The following is an example showing how to work with a multi-dimensional i.e. rectangular array in C# −
Example
using System; namespace Demo { class Program { static void Main(string[] args) { int[,] a = new int[3, 3]; a[0,1]= 1; a[0,2]= 2; a[1,0]= 3; a[1,1]= 4; a[1,2]= 5; a[2,0]= 6; a[2,1]= 7; a[2,2]= 8; int i, j; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { Console.WriteLine("a[{0},{1}] = {2}", i, j, a[i,j]); } } Console.ReadKey(); } } }
Output
a[0,0] = 0 a[0,1] = 1 a[0,2] = 2 a[1,0] = 3 a[1,1] = 4 a[1,2] = 5 a[2,0] = 6 a[2,1] = 7 a[2,2] = 8
Advertisements