Jagged Arrays in C#

 Jagged Arrays

C# arrays are jagged when they hold other arrays. The arrays placed in jagged arrays can have different sizes and dimensions.

With the following code, we generate a single-dimensional array with four other single-dimensional int type arrays:

int[][] jaggedArray = new int[4][];

It is crucial to make C# declare arrays and initialize them with the following code:

jaggedArray[0] = new int[4];

jaggedArray[1] = new int[5];

jaggedArray[2] = new int[3];

We created three single-dimensional arrays: the first one contains 4 integers, the second contains 5 integers, and the last one has 3 integers.

You can make C# initialize arrays without setting their size as well. Then, you have to include their element values by using the initializers:

jaggedArray[0] = new int[] { 7, 2, 5, 3, 8 };

jaggedArray[1] = new int[] { 4, 5, 7, 8 }; 

jaggedArray[2] = new int[] { 14, 18 };

Comments

Popular posts from this blog

Performance Optimization in Sitecore

Strategies for Migrating to Sitecore from legacy or upgrading from older Sitecore

Azure Event Grid Sample code