jagged array c#

// A "multidimensional array" is essentially a matrix occupying one block of memory
// The "jagged array" is an array of arrays 
//  - with no restriction that the latter arrays need to be of the same dimension/length
//  - each of these latter arrays also occupy their own block in memory

int[][] jArray = new int[3][]{
  					new int[2]{1, 2},
					new int[3]{3, 4, 5},
                	new int[4]{6, 7, 8, 9}
            	};

jArray[1][2]; //returns 4

// We can change a whole element of array
jArray[1] = new int[3] { 10, 11, 12 }; 

jArray[1][2]; //returns 11

int[][][] intJaggedArray = new int[2][][] 
                            {
                                new int[2][]  
                                { 
                                    new int[3] { 1, 2 },
                                    new int[2] { 4, 5, 6 } 
                                },
                                new int[1][]
                                { 
                                    new int[3] { 7, 8, 9, 10 }
                                }
                            };

intJaggedArray[0][1][2]; //returns 6

// https://stackoverflow.com/a/4648953/9034699
// https://www.tutorialsteacher.com/csharp/csharp-jagged-array



// The following are multidimensional arrays
// Two-dimensional array. (4 rows x 2 cols)
int[,] array2D = new int[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };
// Three-dimensional array. (4 rows x 2 cols)
int[,,] array3D = new int[,,] { 
  									 { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } },
                                     { { 13, 14, 15, 16 }, { 17, 18, 19, 20 }, { 21, 22, 23, 24 } } 
                                   };
int[,,] array3D = new int[2, 3, 4] { 
  									 { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } },
                                     { { 13, 14, 15, 16 }, { 17, 18, 19, 20 }, { 21, 22, 23, 24 } } 
                                   };

// C# also has jagged arrays

0
5
CharybdeBE 110 points

                                    data_type[][] name_of_array = new data_type[rows][]

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to iterate jagged array c# printing out jagged array c# iterating jagged array c# jagged array initialize c# jagged array c# initialization c# print jagged array c# add elements to jagged array c# what is a jagged array c# 2d array jagged array jagged array in c-sharp how to print jagged array in c# multidimensional array and jagged array in c# jagged array c# declare tranverse jagged array c# declare to jagged array c# jagged array in c sharp jagged string array c# 2d array to jagged array c# initialise jagged array c# jagged int array c# c# initialise jagged array jagged array add function in c# jagged array in c# using double dimensional c# jagged array in c# using double dimensional create 2d jagged array in c# jagged array programs in c# jagged array program in c# jagged array foreach c# c# jagged arrays c# flatten jagged array create jagged array c# c# jagged array structure declaration of jagged array in c# take the indexes from a jagged array c# take a specific array from a jagged array c# c# jaggedt array c# 2D array to jagged array c# jagged array add values declare jagged array in c# define jagged array in c# creating a jagged array without new c# can not initialize a jagged array in c# two dimensional jagged array in c# c# jagged array unlimited c# dynamic jagged array Jagged arrays c# how to use jagged arrays C# initialize new jagged array c# coppy jagged array c# jagged arrays c# how to make a jagged array c# jagged array is a in c# mcq jagged array is a class in c# mcq jagged array is a class in c# jagged array is a pointer in C# c# new syntax initialization for jagged array jagged array decalaration c# jagged array in c# example what is jagged array in c# c# reference jagged array element c# reference jagged array index c# reference jagged array initialise second array c# in jagged array how to go through a jagged array c# Jagged Arrays in c# jagged array in c sharp with examples c# array jagged jagged array using reflection c# c# jagged array initialization jagged array C# simple jagged array program in c# jagged array declaration in c# new jagged array c# in function call new jagged array c# c# jagged array initialize jagged array c# jagged array in c# tutlane jagged array in c#
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source