温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

C#中二维数组的用法

发布时间:2021-08-25 17:13:35 来源:亿速云 阅读:232 作者:chen 栏目:编程语言

本篇内容主要讲解“C#中二维数组的用法”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“C#中二维数组的用法”吧!

C#二维数组

  1. publicclassArray2D...{  

  2. publicstaticvoidmain(String[]args)...{  

  3. intmyInt[][]=newint[5][10];  

  4. //遍历,给数组中的每一个数组赋值  

  5. for(inti=0;i<myInt.length;i++)...{  

  6. for(intj=0;j<myInt[0].length;j++)...{  

  7. myInt[i][j]=i*j;  

  8. }  

  9. }  

  10. System.out.println("myInt.length="+myInt.length+",myInt[0].
    length
    ="+myInt[0].length);  

  11. //输出数组每一维的下限和上限  

  12. for(inti=0;i<myInt.length;i++)...{  

  13. for(intj=0;j<myInt[0].length;j++)...{  

  14. System.out.println("myInt["+i+"]["+j+"]="+myInt[i][j]);  

  15. }  

  16. }  

  17. }  

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

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();  }  }

到此,相信大家对“C#中二维数组的用法”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI