- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
What are jagged arrays in C#?
A Jagged array is an array of arrays in C#. You can declare and initialize it −
int[][] rank = new int[1][]{new int[]{5,3,1}};
The following is an example showing how to work with jagged arrays in C# −
Example
using System; namespace Program { class Demo { static void Main(string[] args) { int[][] rank = new int[][]{new int[]{1,2},new int[]{3,4}}; int i, j; for (i = 0; i < 2; i++) { for (j = 0; j < 2; j++) { Console.WriteLine("a[{0}][{1}] = {2}", i, j, rank[i][j]); } } Console.ReadKey(); } } }
Output
Above, we have a jagged array of 2 array of integers −
int[][] rank = new int[][]{new int[]{1,2},new int[]{3,4}};
Advertisements