- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to access elements from a rectangular array in C#?
To access elements from a rectangular array, you just need to set the index of which you want to get the element. Multi-dimensional arrays are also called rectangular array −
a[0,1]; // second element
The following is an example showing how to work with a rectangular array in C# and access an element −
Example
using System; namespace Demo { class Program { static void Main(string[] args) { int[,] a = new int[3, 3]; a[0,0]= 10; a[0,1]= 20; a[0,2]= 30; a[1,0]= 40; a[1,1]= 50; a[1,2]= 60; a[2,0]= 70; a[2,1]= 80; // accessing element a[2,2]= 90; 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]); } } int ele = a[0,1]; Console.WriteLine("Second element: "+ele); Console.ReadKey(); } } }
- Related Articles
- How to access elements from jagged array in C#?
- How to access elements from an array in C#?
- How to access elements from multi-dimensional array in C#?
- How to access array elements using a pointer in C#?
- How do we access elements from the two-dimensional array in C#?
- How to define a rectangular array in C#?
- How to initialize a rectangular array in C#?
- How to access elements of an array using pointer notation in C#?
- C++ Program to Access Elements of an Array Using Pointer
- Java Program to Access elements from a LinkedList
- How to access an array element in C language?
- C# Program to access tuple elements
- How to get Synchronize access to an Array in C#?
- How to access HTML elements in JavaScript?
- How to print the elements in a reverse order from an array in C?

Advertisements