• 数组


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

    数组隐式继承于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();
    
                }
            }
        }
  • 相关阅读:
    数据库的隔离
    Maven的工程类型有哪些
    Redis中的常用命令哪些
    flume--exec源
    hadoop基本组件原理小总结
    Idea 激活
    hadoop中遇到的各种错误记录
    MySQL认知
    Python爬虫之post请求
    Python爬取ithome的一所有新闻标题评论数及其他一些信息并存入Excel中。
  • 原文地址:https://www.cnblogs.com/lovezhangyu/p/3371749.html
Copyright © 2020-2023  润新知