在C#中int[][] myInt是声明一个交错数组,声明C#二维数组是这么声明int[,]
- classclsArrat2D
- {
- /**<summary>
- ///应用程序的主入口点。
- ///summary>
- [STAThread]
- staticvoidMain(string[]args)
- {
- int[,]myInt=newint[5,10];
- //遍历,给数组中的每一个数组赋值
- for(inti=myInt.GetLowerBound(0);i<=myInt.GetUpperBound(0);i++)
- {
- for(intj=myInt.GetLowerBound(1);j<=myInt.GetUpperBound(1);j++)
- {
- myInt[i,j]=i*j;
- }
- }
- //输出数组每一维的下限和上限
- for(inti=0;i<myInt.Rank;i++)
- {
- Console.WriteLine("{0}{1}{2}",i,myInt.GetLowerBound(i),myInt.GetUpperBound(i));
- }
- //遍历,输出二维数组中每一个元素的个数
- for(inti=myInt.GetLowerBound(0);i<=myInt.GetUpperBound(0);i++)
- {
- for(intj=myInt.GetLowerBound(1);j<=myInt.GetUpperBound(1);j++)
- {
- Console.WriteLine("myInt[{0},{1}]={2}",i,j,myInt[i,j]);
- }
- }
- Console.ReadLine();
- }
- }