美图齐众专注资阳网站设计 资阳网站制作 资阳网站建设
资阳网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

简单描述C#二维数组

C#有很多值得学习的地方,这里我们主要介绍C#二维数组,包括介绍声明C#二维数组是这么声明int[,] myInt等方面。

成都创新互联公司服务项目包括唐山网站建设、唐山网站制作、唐山网页制作以及唐山网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,唐山网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到唐山省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

C#二维数组

 
 
 
  1. publicclassArray2D...{  
  2. publicstaticvoidmain(String[]args)...{  
  3. intmyInt[][]=newint[5][10];  
  4. //遍历,给数组中的每一个数组赋值  
  5. for(inti=0;i;i++)...{  
  6. for(intj=0;j[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;i++)...{  
  13. for(intj=0;j[0].length;j++)...{  
  14. System.out.println("myInt["+i+"]["+j+"]="+myInt[i][j]);  
  15. }  
  16. }  
  17. }  

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

 
 
 
  1. classclsArrat2D  
  2. {  
  3. /**//// 
  4. ///应用程序的主入口点。  
  5. /// summary> 
  6. [STAThread]  
  7. staticvoidMain(string[]args)  
  8. {  
  9. int[,]myInt=newint[5,10];  
  10. //遍历,给数组中的每一个数组赋值  
  11. for(inti=myInt.GetLowerBound(0);i<=myInt.GetUpperBound(0);i++)  
  12. {  
  13. for(intj=myInt.GetLowerBound(1);j<=myInt.GetUpperBound(1);j++)  
  14. {  
  15. myInt[i,j]=i*j;  
  16. }  
  17. }  
  18. //输出数组每一维的下限和上限  
  19. for(inti=0;i;i++)  
  20. {  
  21. Console.WriteLine("{0}{1}{2}",i,myInt.GetLowerBound(i),myInt.GetUpperBound(i));  
  22. }  
  23. //遍历,输出二维数组中每一个元素的个数  
  24. for(inti=myInt.GetLowerBound(0);i<=myInt.GetUpperBound(0);i++)  
  25. {  
  26. for(intj=myInt.GetLowerBound(1);j<=myInt.GetUpperBound(1);j++)  
  27. {  
  28. Console.WriteLine("myInt[{0},{1}]={2}",i,j,myInt[i,j]);  
  29. }  
  30. }  
  31. Console.ReadLine();  
  32. }  

以上介绍C#二维数组。


当前名称:简单描述C#二维数组
网址分享:http://www.zsjierui.cn/article/cdhjooi.html