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 :: unity scene switch 
Csharp :: listview inter thread operation not valid 
Csharp :: predicate EF Core search query 
Csharp :: run in new thread C# 
Csharp :: c# Modulo 10^9+7 (1000000007) 
Csharp :: start a particle effect when a button is pushed 
Csharp :: decimal operator in Convert.toDouble() C# 
Csharp :: c# merge two lists as queryable 
Csharp :: program.cs entity framework 
Csharp :: unity draw waypoins path 
Csharp :: winform fixed size 
Csharp :: C# top down view movement 
Csharp :: unity basic public options 
Csharp :: Comparing Arrays using LINQ in C# 
Csharp :: unity datetime to string 
Csharp :: unity magnetize a 3d object to cursor 
Csharp :: Block iFrames | How to Stop Your Website From Being iFramed 
Csharp :: find gameobject by name in root 
Csharp :: how to find the biggest number in c# 
Csharp :: camera in raylib c# 
Csharp :: how to make rabbitmq start and stop base on c# services 
Csharp :: concatenate two lists in c# 
Csharp :: faucongz 
Csharp :: scaffold db 
Csharp :: summernote dropdown plugin 
Csharp :: c# convert list to string and back 
Csharp :: maximum sum subarray c# 
Csharp :: c# exception middleware 
Csharp :: Triangle perimeter 
Csharp :: c# async task constructor 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =