C#学习笔记:foreach遍历变长数组
对变长数组使用foreach循环时,通常都要嵌套循环,才能得到该数据。
static void Main(string[] args)
{
int[][] newArarry={new int[] {1},
new int[] {1,2},
new int[] {1,2,3},
new int[] {1,2,3,4},
new int[] {1,3},
new int[] {1,2,3,4,5},
new int[] {2,3,4},
new int[] {3,5}};
foreach(int[] newArarry1 in newArarry)
{
foreach(int newArarry2 in newArarry1)
{
Console.Write(newArarry2);
}
}
Console.ReadKey();
{
int[][] newArarry={new int[] {1},
new int[] {1,2},
new int[] {1,2,3},
new int[] {1,2,3,4},
new int[] {1,3},
new int[] {1,2,3,4,5},
new int[] {2,3,4},
new int[] {3,5}};
foreach(int[] newArarry1 in newArarry)
{
foreach(int newArarry2 in newArarry1)
{
Console.Write(newArarry2);
}
}
Console.ReadKey();
作者:Jason_z(开发者的网上家园 - 博客园)
出处:http://www.cnblogs.com/Jason_z/
文章版权归本人所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。