zoukankan      html  css  js  c++  java
  • 数组

    数组可以分为一维数组、二维数组、三维数组以及多维数组。

    数组隐式继承于System.Array抽象类,而System.Array又继承于System.Object,所以数组是引用类型。

    初始化一维数组:string[] TestArray=new string[30]

    初始化二维数组:string[,] TestArrary=new string[2,3]{{"a","b","c"},{"d","e","f"}}

     class Program
        {
            static void Main(string[] args)
            {
                string[,] TestArray = new string[2, 3] { { "a","b","c"}, {"d","e","f" } };
                TestArray[0, 0] = "aaa";
                string name=TestArray[0,0];
                Console.WriteLine(TestArray[0,0]);
             
                string[,] Name = new string[4, 5];
                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 5; j++)
                    {
                        Name[i, j] ="["+i.ToString()+","+j.ToString()+"]";
                    }
                }
               for (int i = 0; i <4; i++)
                {
                    for (int j = 0; j <5; j++)
                    {
                        Console.Write(Name[i,j]);
                    }
                    Console.WriteLine();
                }
               Console.ReadLine();
            }
        }

    简单的二维数组售票系统

    class Program
        {
            static void Main(string[] args)
            {
                string[,] SaleTicket=new string[5,6];
                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        SaleTicket[i, j] = "【 空 】";
                        
                    }
                    
                }
                Console.WriteLine("请输入要选择的座位号格式为(0,1),输入Q退出");
                string Input = Console.ReadLine();
                while(Input!="q")
                {
                    string[] strNew = Input.Split(',');
                    int One = int.Parse(strNew[0]);
                    int Two = int.Parse(strNew[1]);
                    SaleTicket[One, Two] = "【 已售】";
                    System.Console.Clear();
                    for (int i = 0; i <5; i++)
                    {
                        for (int j = 0; j < 6; j++)
                        {
                            Console.Write(SaleTicket[i,j]);
                        }
                        Console.WriteLine();
                    }
                    Console.WriteLine("请输入要选择的座位号格式为(0,1),输入Q退出");
                      Input = Console.ReadLine();
    
                }
            }
        }
  • 相关阅读:
    2019总结及2020计划
    蓝牙BLE连接与操作
    Android蓝牙操作
    Cannot use JSX unless the '--jsx' flag is provided.
    PyQt打包可执行文件
    Springboot项目报错【java.base/jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to java.base/java.net.URLClassLoader】
    typescript枚举字符串型不能使用函数问题
    beautifulsoap常用取节点方法
    numpy常用矩阵操作
    MYSQL 碎片查询
  • 原文地址:https://www.cnblogs.com/lovezhangyu/p/3371749.html
Copyright © 2011-2022 走看看