翻阅古今
//一维数组int[] iArray = new int[] { 1, 2, 3, 45, 6 };foreach (int i in iArray)Console.Write(i.ToString() + ",");Console.WriteLine("\n\n");//2级数组int[,] i2Array = new int[,] { { 1, 2 }, { 3, 4 } };foreach (int i1 in i2Array){Console.Write(i1.ToString() + ",");}Console.WriteLine("\n\n");//交错数组int[][] CrossArray = new int[3][] { new int[]{ 1, 2 }, new int[]{ 3, 4, 5 }, new int[]{ 6, 7, 8, 9 } };foreach (int[] c in CrossArray){foreach (int i in c)Console.Write(i.ToString() + ",");Console.Write("\n");}
牛魔王的故事
static void Main(string[] args){var oneDimensionsArray = new int[] { 1, 2, 3, 4 };var twoDimensionsArray = new int[,] { {1,2},{3,4},{5,6}};var jaggedArray = new int[3][] { new[] { 1 }, new[] { 2, 3 }, new[] { 4, 5, 6 } };Console.WriteLine("遍历一维数组");//遍历一维数组foreach (var i in oneDimensionsArray){Console.WriteLine(i);}Console.WriteLine("遍历二维数组");//遍历二维数组foreach (var i in twoDimensionsArray){Console.WriteLine(i);}Console.WriteLine("遍历交错数组");//遍历交错数组foreach (var arr in jaggedArray){foreach (var i in arr){Console.WriteLine(i);}}}