zoukankan      html  css  js  c++  java
  • c#多维数组

     多维数组并不常用,我觉得倒不如用xml还好

    代码
    class ArrayTest
        {

            
    public void TestArray(){    
           

              
    //写法一:
                
    //String[, ,] items = new String[,,] { 
                
    //    { 
                
    //        { "A1", "A2", "A3", "A4", "A5" }, 
                
    //        { "B1", "B2", "B3", "B4", "B5" }, 
                
    //        { "C1", "C2", "C3", "C4", "C5" }, 
                
    //        { "D1", "D2", "D3", "D4", "D5" }
                
    //    },
                
    //    { 
                
    //        { "E1", "E2", "E3", "E4", "E5" }, 
                
    //        { "F1", "F2", "F3", "F4", "F5" }, 
                
    //        { "G1", "G2", "G3", "G4", "G5" },
                
    //        { "H1", "H2", "H3", "H4", "H5" }
                
    //    }
                
    //};

                
    //写法二:
                
    //String[, ,] items ={ 
                
    //    { 
                
    //        { "A1", "A2", "A3", "A4", "A5" }, 
                
    //        { "B1", "B2", "B3", "B4", "B5" }, 
                
    //        { "C1", "C2", "C3", "C4", "C5" }, 
                
    //        { "D1", "D2", "D3", "D4", "D5" }
                
    //    },
                
    //    { 
                
    //        { "E1", "E2", "E3", "E4", "E5" }, 
                
    //        { "F1", "F2", "F3", "F4", "F5" }, 
                
    //        { "G1", "G2", "G3", "G4", "G5" },
                
    //        { "H1", "H2", "H3", "H4", "H5" }
                
    //    }
                
    //};

                
    //写法三:
                String[, ,] items = new String[2,4,5]{ 
                    { 
                        { 
    "A1""A2""A3""A4""A5" }, 
                        { 
    "B1""B2""B3""B4""B5" }, 
                        { 
    "C1""C2""C3""C4""C5" }, 
                        { 
    "D1""D2""D3""D4""D5" }
                    },
                    { 
                        { 
    "E1""E2""E3""E4""E5" }, 
                        { 
    "F1""F2""F3""F4""F5" }, 
                        { 
    "G1""G2""G3""G4""G5" },
                        { 
    "H1""H2""H3""H4""H5" }
                    }
                };

                Console.WriteLine(items.Rank);
    //输出3,rank从1开始计数,但表示某一个秩(维度)从下标0开始
                
                Console.WriteLine(
    "items.GetUpperBound(0)="+items.GetUpperBound(0));//输出1
                Console.WriteLine("items.GetUpperBound(1)=" + items.GetUpperBound(1));//输出3
                Console.WriteLine("items.GetUpperBound(2)=" + items.GetUpperBound(2));//输出4        


                Console.WriteLine(
    "items.GetLowerBound(0)=" + items.GetLowerBound(0));//输出0
                Console.WriteLine("items.GetLowerBound(1)=" + items.GetLowerBound(1));//输出0
                Console.WriteLine("items.GetLowerBound(2)=" + items.GetLowerBound(2));//输出0

                Console.WriteLine(
    "遍历输出");
                
    for (int i = 0; i < items.Rank; i++)
                {
                    Console.WriteLine(
    "items.GetUpperBound(" + i + ")=" + items.GetUpperBound(i));
                    Console.WriteLine(
    "items.GetLowerBound(" + i + ")=" + items.GetLowerBound(i));                
                }

                
    for (int i = items.GetLowerBound(0); i <= items.GetUpperBound(0); i++)
                {
                    
    for (int j = items.GetLowerBound(1); j <= items.GetUpperBound(1);j++ )
                    {
                        
    for (int k = items.GetLowerBound(2); k <=items.GetUpperBound(2);k++ )
                        {
                            Console.Write(items[i,j,k]
    +" ");                        
                        }
                        Console.WriteLine();
                    } 
                }          

                Console.WriteLine(
    "数组中元素的总数目(length):"+items.Length);          
                Console.ReadLine();
            }
        }

  • 相关阅读:
    vue项目实践-添加axios封装api请求
    travis-ci 中运行 puppeteer
    ubuntu 16.04 TLS 安装VNC
    duilib bkimage 属性
    Android后台服务拍照
    mongodb 设置用户密码权限
    App爬虫神器mitmproxy和mitmdump的使用
    insserv: Script <name> is broken: incomplete LSB comment.
    ubuntu ssh root登陆
    virtualbox 迁移虚拟机存储位置
  • 原文地址:https://www.cnblogs.com/Fskjb/p/1736359.html
Copyright © 2011-2022 走看看