zoukankan      html  css  js  c++  java
  • 获取多维数组的维度

    实现效果:

      

    知识运用:

      获取数组的行与列运用了Array类的GetUpperBound(int dimension)方法,用来获取指定维度的上限;

      使用GetUpperBound(0)+1获取数组的行数,使用GetUpperBound(1)+1获取数组的列数; 

    实现代码:

            private void button1_Click(object sender, EventArgs e)
            {
                textBox1.Clear();    //清空之前内容
                Random ran=new Random();
                string[,] str_array = new string[ran.Next(2, 10), ran.Next(2, 10)];//定义随机数组
                    label1.Text = string.Format("生成了{0}行{1}列的数组",
                        str_array.GetUpperBound(0)+1,str_array.GetUpperBound(1)+1);
                    show_array(str_array);  //调用显示
            }
            //定义显示方法
            public void show_array(string[,] arr) { 
                for(int i=0;i<arr.GetUpperBound(0)+1;i++){
                    for (int j = 0; j < arr.GetUpperBound(1) + 1;j++ )
                    {
                        arr[i,j] = string.Format("{0},{1}  ",i,j);
                        textBox1.AppendText(arr[i, j]);
                    }       textBox1.AppendText("
    ");  //进行换行
                } textBox1.BackColor = Color.Honeydew;  //添加背景色
            }
    
  • 相关阅读:
    数据结构做题一些总结
    ExecuteNoQuery执行, 报错“go”附近有语法错误。
    EF总结
    哨兵模式
    Redis 发布订阅
    Redis 持久化
    Redis 事务 和乐观锁
    缓存穿透和雪崩
    Redis 基础知识
    Redis 三种特殊的数据类型
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10055405.html
Copyright © 2011-2022 走看看