/* Example10_8.cs illustrates the use of a three-dimensional rectangular array */ using System; class Example10_8 { public static void Main() { // create the galaxy array int[,,] galaxy = new int [10, 5, 3]; // set two galaxy array elements to the star's brightness galaxy[1, 3, 2] = 3; galaxy[4, 1, 2] = 9; // display the Rank and Length properties of the galaxy array Console.WriteLine("galaxy.Rank (number of dimensions) = " + galaxy.Rank); Console.WriteLine("galaxy.Length (number of elements) = " + galaxy.Length); // display the galaxy array elements, but only display elements that // have actually been set to a value (or "contain stars") for (int x = 0; x < galaxy.GetLength(0); x++) { for (int y = 0; y < galaxy.GetLength(1); y++) { for (int z = 0; z < galaxy.GetLength(2); z++) { if (galaxy[x, y, z] != 0) { Console.WriteLine("galaxy[" + x + ", " + y + ", " + z +"] = " + galaxy[x, y, z]); } } } } } }
C#数组实例
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
C# 数组
C#数组
数组 C#数组 -
C# 封装实例
今天这个主题也是帮群友解答的一个问题,如下图,有很多方法都要重复利用一段代码,所以他需要把它封装成为一个方法
封装 访问修饰符 属性值 面向对象 c# -
C#方法实例
/*程序的功能是: 等待用户输入,当
System -
C#反射实例
C#反射的入门学习首先要明白C#反射提供了封装程序集、模块和类型的对象等等。那么这样可以使用反射动态创建类型
c# 命名空间 程序集 字段 数据类型 -
c# 重载实例
☆C#的运算符定义只有四
c# string microsoft object equals