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();
    
                }
            }
        }
  • 相关阅读:
    ecshop 调用指定分类的推荐,热卖,新品
    ecshop 首页调用指定类产品
    html常用笔记
    ecshop 修改flash图片大小
    ecshop 删除随机版权
    Java Web(一) Servlet详解!!
    Git使用总结
    git clone命令使用
    Lucene学习总结之四:Lucene索引过程分析
    Lucene学习总结之二:Lucene的总体架构
  • 原文地址:https://www.cnblogs.com/lovezhangyu/p/3371749.html
Copyright © 2011-2022 走看看