using System.IO; using System; class Program { int[] factors; int[] count; int[][] jagg; static void Main() { Program pg = new Program(); pg.factors = new int[3] {100, 200, 300}; pg.count = new int[3] {3, 4, 5}; pg.MakeJaggedArray(pg.factors, pg.count); pg.ShowJaggedArray(pg.jagg); Console.WriteLine(); pg.ShowJaggedSingle(pg.jagg, 0); } void MakeJaggedArray(int[] myfactors, int[] mycount) { jagg = new int[myfactors.Length][]; for(int i=0; i < myfactors.Length; i++) { jagg[i] = new int[mycount[i]]; for(int j=0; j< mycount[i]; j++) { jagg[i][j] = myfactors[i] + 3 * j; } } } void ShowJaggedArray(int[][] myJagg) { for(int i=0; i < myJagg.Length; i++) { for(int j=0; j< myJagg[i].Length; j++) { Console.Write("jagg[{0}][{1}] : ",i,j); Console.WriteLine(myJagg[i][j]); } } } void ShowJaggedSingle(int[][] myJagg, int index) { for(int i=0; i < myJagg.Length; i++) { Console.Write("jagg[{0}][",i); for(int j=0; j< myJagg[i].Length; j++) { Console.Write(myJagg[i][j] + "\t"); } Console.WriteLine("\b]"); } } }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more