Write a note on “Array of Arrays”? ( .NET Interview questions with answers)

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[2]; // 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[0] = 1;
mainarr[1] = 2;

So if we visualize the array picture it looks something as shown below. You have two array values with “0” and “1” index.

1

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[1]); //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[2][];

So now we can set more array structure inside other array as shown in the below code.

mainarr[0] = new int[2];
mainarr[1] = new int[3];

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”.

2

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.

Console.WriteLine(mainarr[1][2]);

Going for .NET and C# interview start preparing from the below video.

Advertisements

About c# and .NET Interview questions

This blog is for developers who want to crack .NET and C# interviews. It has all tips and tricks needed to crack .NET interviews , C# interview , SQL Server interview , Java interview , WCF Interview , Silverlight interview , WPF interview , LINQ interview , Entity framework Interview. Do not forget to watch our Learn step by step video series. Learn MVC in 16 hours:- https://www.youtube.com/watch?v=Lp7nSImO5vk Learn AngularJS Step by Step:- https://www.youtube.com/watch?v=0kmdjqgO9IY Learn Design Pattern in 8 hours:- https://www.youtube.com/watch?v=YDobmucohqk Learn C# and .NET in 60 days:- https://www.youtube.com/watch?v=yh2SrzCkNQA Learn MSBI in 32 hours:- https://www.youtube.com/watch?v=mGPJx3ocFgg Learn SharePoint Step by Step in 8 hours:- https://youtu.be/C2fW76SwJNU
This entry was posted in Uncategorized and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s