C# Jagged Arrays Tutorial with Examples

C# Jagged Arrays Tutorial with Examples

Jagged Arrays in C#

In this post,we will learn about Jagged Arrays in C# with an example.

Now in this post, I will explain Jagged Arrays in C# with appropriate example. A Jagged array is an array of arrays. Jagged Arrays is also called as “array of arrays” because its elements are arrays. The element size of jagged array can be different.

Types of Array in C#.Net

Arrays can be divided into the following four categories.

Declaration of Jagged array

Declare jagged array that has two elements.

READ :  Routing in laravel 6 Web Application Tutorial

int[][] arr = new int[2][];

Initialization of Jagged array

Write below lines to initialize jagged array. The size of elements can be different.

E-junkie: Sell digital downloads online

E-junkie Provides a Copy-paste buy-now, and cart buttons for selling downloads, codes and tangible products on any website, blog, social media, email and messenger!

Also see:

  1. The Top 10+ Best Webinar Software Platforms For 2020-2021
  2. Build Your Future Godaddy Careers And Jobs
  3. Introduction To Web Hosting Services

arr[0] = new int[2];  
arr[1] = new int[3];

Now create Console Application in Visual Studio and write below lines of code in it.

using System;
using System.Collections;
using System.Collections.Generic;

namespace ConsoleDemo
    class Program
        static void Main(string[] args)
            // Jagged Array Example

            int[][] _JaggedArray = new int[2][];// Declare jagged array  

            _JaggedArray[0] = new int[] { 11, 21, 31, 41 };// Initialize the array with value       
            _JaggedArray[1] = new int[] { 42, 52, 62, 72, 83, 93 };

            // Raed and print array elements  
            for (int i = 0; i < _JaggedArray.Length; i++)
                for (int j = 0; j < _JaggedArray[i].Length; j++)
                    System.Console.Write(_JaggedArray[i][j] + " ");

OutPut :

11 21 31 41
42 52 62 72 83 93

ASP.NET Example With Tutorial

Read :

READ :  VueJs Smart Table with Add Edit Delete Records - Dynamic Table


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Jagged Arrays in C#.
I would like to have feedback on my Infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

We hope This Post can help you…….Good Luck!.