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();
    
                }
            }
        }
  • 相关阅读:
    讨论下NOSQLDB使用场景的问题
    控制反转IOC与依赖注入DI dodo
    ASp.net中Froms验证方式 dodo
    SQL Server 2008阻止保存要求重新创建表的更改 dodo
    依赖注入容器Unity介绍 dodo
    mvc UrlHelper dodo
    ASP.NET MVC 使用TempData dodo
    ASP.NET MVC的生命周期与网址路由 dodo
    强制将IE,Chrome设置为指定兼容模式来解析 dodo
    LINQ to XML 常用操作(转) dodo
  • 原文地址:https://www.cnblogs.com/lovezhangyu/p/3371749.html
Copyright © 2011-2022 走看看