3 回答
TA贡献1780条经验 获得超5个赞
//一维数组
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");
}
TA贡献1802条经验 获得超4个赞
foreach(var a in array)
{
this.text=a.tostring;
}
for(int i =0;i<array.upbound;i++)
{
this.text=array[i].tostring;
}
TA贡献1830条经验 获得超3个赞
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);
}
}
}
- 3 回答
- 0 关注
- 668 浏览
添加回答
举报