Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace random
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[][] jaggedArray = new int[3][];
- //declaring jaggedArray without specifying values, just the size of the arrays.
- jaggedArray[0] = new int[5];
- jaggedArray[1] = new int[3];
- jaggedArray[2] = new int[2];
- //declaing jaggedArry and specifying values without stating the size of array.
- jaggedArray[0] = new int[] { 2, 3, 5, 7, 11 };
- jaggedArray[1] = new int[] { 1, 2, 3 };
- jaggedArray[2] = new int[] { 13, 21 };
- // alternative method:
- int[][] jaggedArray2 = new int[][]
- {
- new int[] { 2, 3, 5, 7, 11 },
- new int[] { 1, 2, 3 },
- new int[] { 13, 21 }
- };
- Console.WriteLine($"The value in the middle of the first entry is {jaggedArray2[0][2]}\n");
- //Print to Console all values in jaggedArray2
- for (int i = 0; i< jaggedArray2.Length; i++) //first for loop is getting the 1st, 2nd, and 3rd array in jaggedArray2
- {
- Console.WriteLine("Element {0}", i);
- for (int j = 0; j < jaggedArray2[i].Length; j++)
- Console.WriteLine("{0} ", jaggedArray2[i][j]); //position 'i', which is going to be 0, 1 or 2
- } //position 'j', which is going to be 0-4, 0-2, then 0-1
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement