java与c#中二维数组的区别

[color=darkred]java与c#中二维数组的区别[/color][color=green][/color]

public class Array2D...{
public static void main(String[] args)...{
int myInt[][]=new int[5][10];
//遍历,给数组中的每一个数组赋值
for(int i=0;i<myInt.length;i++)...{
for(int j=0;j<myInt[0].length;j++)...{
myInt[i][j]=i*j;
}
}
System.out.println ("myInt.length="+myInt.length+",myInt[0].length="+myInt[0].length);
//输出数组每一维的下限和上限
for(int i=0;i<myInt.length;i++)...{
for(int j=0;j<myInt[0].length;j++)...{
System.out.println ("myInt["+i+"]["+j+"]="+myInt[i][j]);
}
}
}
}



在C#中int[][] myInt是声明一个交错数组,声明二维数组是这么声明int[,] myInt,上面的代码如果换成C#的,需要如下表示:


class clsArrat2D
{
/** <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
int[,] myInt=new int[5,10];
//遍历,给数组中的每一个数组赋值
for(int i=myInt.GetLowerBound(0);i<=myInt.GetUpperBound(0);i++)
{
for(int j=myInt.GetLowerBound(1);j<=myInt.GetUpperBound(1);j++)
{
myInt[i,j]=i*j;
}
}
//输出数组每一维的下限和上限
for(int i=0;i<myInt.Rank;i++)
{
Console.WriteLine("{0} {1} {2}", i, myInt.GetLowerBound(i), myInt.GetUpperBound(i));
}
//遍历,输出二维数组中每一个元素的个数
for(int i=myInt.GetLowerBound(0);i<=myInt.GetUpperBound(0);i++)
{
for(int j=myInt.GetLowerBound(1);j<=myInt.GetUpperBound(1);j++)
{
Console.WriteLine("myInt[{0},{1}]={2}",i,j,myInt[i,j]);
}
}
Console.ReadLine();
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值