This array interview question was asked in Wipro banglore to a .NET fresher.
Array of Array’s is also termed as “Jagged” array. Arrays are zero indexed, means if you create an array of size 2 the first element starts at “0” and the second element starts at “1”.
For example below is a simple C# array code with a size of value “2”.
int mainarr = new int; // Array with 2 values
So if you want to set values, you need to specify “0” for the first element and “1” for the second element.
mainarr = 1; mainarr = 2;
So if we visualize the array picture it looks something as shown below. You have two array values with “0” and “1” index.
If you want to display the second element you need to specify “1” in the index as shown in the below code.
Console.WriteLine(mainarr); //Displays the 2nd element from the array
Now to create array of array ( jagged array) you need to put two square brackets “”. The below code has created an array with length of 2 and every array index can have more array’s inside it.
int mainarr = new int;
So now we can set more array structure inside other array as shown in the below code.
mainarr = new int; mainarr = new int;
So if visualize the array structure it looks as shown below. We have one main array of length 2 and each index having an array inside it. The first index i.e. “0” has array size of “2” and the second array index having a size of “3”.
So if you want to display the third array from the main array’s second element you can refer as shown in the below code.
Going for .NET and C# interview start preparing from the below video.