Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

jagged array c#

// C# program to illustrate the declaration 
// and Initialization of Jagged Arrays
using System;
  
class GFG {
      
    // Main Method
    public static void Main()
    {
          
        // Declare the Jagged Array of four elements:
        int[][] jagged_arr = new int[4][];
  
        // Initialize the elements
        jagged_arr[0] = new int[] {1, 2, 3, 4};
        jagged_arr[1] = new int[] {11, 34, 67};
        jagged_arr[2] = new int[] {89, 23};
        jagged_arr[3] = new int[] {0, 45, 78, 53, 99};
  
        // Display the array elements:
        for (int n = 0; n < jagged_arr.Length; n++) {
  
            // Print the row number
            System.Console.Write("Row({0}): ", n);
  
            for (int k = 0; k < jagged_arr[n].Length; k++) {
  
                // Print the elements in the row
                System.Console.Write("{0} ", jagged_arr[n][k]);
            }
            System.Console.WriteLine();
        }
    }
}
Comment

c# jagged array initialization

// In C#, a jagged array consists of multiple arrays as its element
//Syntax: 
//dataType[ ][ ] nameOfArray = new dataType[rows][ ];


using System;

namespace JaggedArray {
  class Program {
    static void Main(string[] args) {

     // create a jagged array
     int[ ][ ] jaggedArray = {
         new int[] {1, 3, 5},
         new int[] {2, 4},
      };

     // print elements of jagged array
     Console.WriteLine("jaggedArray[1][0]: " + jaggedArray[1][0]);
     Console.WriteLine("jaggedArray[1][1]: " + jaggedArray[1][1]);

     Console.WriteLine("jaggedArray[0][2]: " + jaggedArray[0][2]);

     Console.ReadLine();
    }    
  }
}
Comment

jagged array c#

jagged array is also known as varriable size array. Can store data of any size.

int[][] jagged_arr = new int[3][];
jagged_arr[0] = new int[] {1, 7, 9, 22};
jagged_arr[1] = new int[] {11, 34, 67};
jagged_arr[2] = new int[] {110, 24};
Comment

PREVIOUS NEXT
Code Example
Csharp :: operator -- c# 
Csharp :: turn list of string to csv c# 
Csharp :: lock pc using c# 
Csharp :: c# input 
Csharp :: play animation through script unity 
Csharp :: how to check that string has only alphabet in c# 
Csharp :: c# get directory name from filename 
Csharp :: c# OrderBy desc 
Csharp :: Pass Querystring in C# httpclient 
Csharp :: c# turn negative number into positive 
Csharp :: c# dictionary values to list 
Csharp :: c# round double 
Csharp :: c# list declaration 
Csharp :: c# add object to array 
Csharp :: c# and in if statement 
Csharp :: switch expression c# multiple cases 
Csharp :: C# monogodb 
Csharp :: hcf of numbers 
Csharp :: aspx import namespace 
Csharp :: get what week of the month c# 
Csharp :: .net core partial view with model 
Csharp :: an existing connection was forcibly closed by the remote host. .net core 
Csharp :: c# video to frames 
Csharp :: subtract days c# 
Csharp :: random in f# 
Csharp :: c# add time to datetime 
Csharp :: .net core identity get user id 
Csharp :: c# clear an array 
Csharp :: unity add button 
Csharp :: c# function 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =