Using system;using system.collections.generic;using system.linq;using system.text;using system.threading.tasks;namespace consoleapplication1{ class program{ static void main (String[] args) { //declares a one-dimensional array and outputs console.writeline ("Ouput array."); string []friendNames = {"Robert", "Mike", "Jeremy" }; int i; console.writeline ("here Are {0} of my friends ", friendnames.length); for (I = 0; i < friendnames.length;i++ ) { console.writeline (Friendnames[i]);} console.writeline ("ouput double array. "); //declares a two-dimensional array and outputs double[,] hillheight = { {1,2,3,4},{ 5,6,7,8}}; foreach (double Height in hillheight) { console.writeline ("{0}", height);} console.writeline ("Ouput divisor array. "); //declares a jagged array, an array ofArray //divisor1to10, which is used to protect the int[] element, not an int element; //need to traverse the int[] element int[][] divisor1To10 = { new int []{1}, new int []{1,2}, new int []{1,3}, new int []{1,2,4 }, new int []{1,5}, new int []{1,2,3,6}, new int []{1,7}, new int []{1,2,4,8}, new int []{1,3,9}, new int []{ 1,2,5,10}}; foreach (int[] Divisorofint in divisor1to10) { foreach (Int divisor in divisorofint) { console.writeline (divisor);}} console.readline (); }}}
This article comes from the "Ricky's blog" blog, please be sure to keep this source http://57388.blog.51cto.com/47388/1650618
8. C #--one-dimensional arrays, two-dimensional arrays, jagged arrays