
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How to 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
- Related Articles
- How to initialize a rectangular array in C#?
- How to access elements from a rectangular array in C#?
- How to define an array in C#?
- How to define a single-dimensional array in C Sharp?
- How to define an array class in C#?
- How to define the rank of an array in C#?
- How to define a variable in C++?
- How to define a structure in C#
- How to define constants in C++?
- How to define methods in C#?
- How to define namespaces in C#?
- How to define variables in C#?
- How to define an array size in java without hardcoding?
- How to define custom methods in C#?
- How to define jagged arrays in C#?

Advertisements