c# 中使用foreach和for遍历 一维数组; 二维数组; 交错数组;
//数字可以随便给!!一维数组;int[]array={"随便举一些例子"}二维数组;int[,]name=newint[4,6]交错数组;int[][]name2=ne...
//数字可以随便给!!
一维数组;int[ ] array={"随便举一些例子"}
二维数组; int[ , ] name = new int [ 4,6 ]
交错数组; int [ ] [ ] name2 = new int[ 3 ][ ] 展开
一维数组;int[ ] array={"随便举一些例子"}
二维数组; int[ , ] name = new int [ 4,6 ]
交错数组; int [ ] [ ] name2 = new int[ 3 ][ ] 展开
3个回答
展开全部
//一维数组
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");
}
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);
}
}
}
{
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);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
foreach(var a in array)
{
this.text=a.tostring;
}
for(int i =0;i<array.upbound;i++)
{
this.text=array[i].tostring;
}
{
this.text=a.tostring;
}
for(int i =0;i<array.upbound;i++)
{
this.text=array[i].tostring;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询