zoukankan      html  css  js  c++  java
  • C#数组实例

    /*
      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]);
              }
            }
          }
        }
    
      }
    
    }
    
  • 相关阅读:
    面向对象———类
    二维数组简单使用
    数组——算法
    第6章 约束满足问题CSP
    第5章 对抗搜索
    第4章 超越经典的搜索
    140303 命令行选项 ccf
    150904 高速公路 ccf
    170304 地铁修建 ccf
    vector容器
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2038272.html
Copyright © 2011-2022 走看看