Multidimensional & Jagged Arrays (Exercise) – Learn C#

7  comments

This is an exercise for this YouTube video.

Happy learning and good luck!

[qsm quiz=6]

 

Assignment: Make a 2D jagged array and a 2D multidimensional array with the exact same content using a collection initializer.

 

Click to see the answer
int[][] jagged = new int[][]
{
    new int[] {1, 2, 3, 4},
    new int[] { 5, 6, 7, 8}
};

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

 

 

Assignment: Print out the contents of both of the arrays from the previous assignment.

 

Click to see the answer
for (int i = 0; i < jagged.Length; i++)
    for (int j = 0; j < jagged[i].Length; j++)
        Console.WriteLine(jagged[i][j]);

for (int i = 0; i < multidimensional.GetLength(0); i++)
    for (int j = 0; j < multidimensional.GetLength(1); j++)
        Console.WriteLine(multidimensional[i, j]);

 

About the author 

Matt Rešetár

Matt is an app developer with a knack for teaching others. Working as a Flutter Developer at LeanCode and a developer educator, he is set on helping other people succeed in their Flutter app development career.

You may also like

Flutter UI Testing with Patrol

Flutter UI Testing with Patrol
  • I see you don’t monetize your site, don’t waste your traffic, you can earn additional cash every month because you’ve got high quality content.

    If you want to know how to make extra $$$, search for: Boorfe’s tips best adsense alternative

  • Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
    >