• 数组浅谈


    数组是引用类型,数组和集合都包含了同一个类型的多个对象(如果需要包含不同类型的多个对象需要使用元祖类型)

    数组在指定了大小后就不可用在改变

    也可以自定义数组类型

    ////class Array
    ////{
    //// static void Main()
    //// {
    //// int[] a1 = new int[] { 1,2,3 };
    //// int[,] a2 = new int[,] { { 1 }, { 4 } };
    //// int[,,] a3 = new int[, , ]{{{1},{1},{1}},{{5},{5},{5} }};
    //// int[,,] a4=new int[,,] { { { 1, 2, 3 },{ 4, 5, 6 },{ 7, 8, 9 } }, { { 1, 2, 3 },{ 4, 5, 6 },{ 7, 8, 9 } } };
    //// int[][] j2 = new int[3][];
    //// j2[0] = new int[] { 1, 2, 3 };
    //// j2[1] = new int[] { 1, 2, 3, 4, 5, 6 };
    //// j2[2] = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    //// }

    ////}
    ////class test
    ////{
    //// static void Main()
    //// {
    //// int[] arr = new int[5];
    //// for (int i = 0; i < arr.Length; i++) {
    //// arr[i] = i + i;
    //// }
    //// for (int i = 0; i < arr.Length; i++) {
    //// Console.WriteLine("arr[{0}]={1}",i,arr[i]);

    //// }
    //// Console.Read();
    //// }

    ////}
    //public class Person
    //{
    // public string FirstName { get; set; }
    // public string LastName { get; set; }
    // public override string ToString()
    // {
    // return String.Format("{0},{1}", FirstName, LastName);
    // }

    // Person[] myPersons2 =
    // {
    //new Person { FirstName="Ayrton", LastName="Senna"},
    //new Person { FirstName="Michael", LastName="Schumacher"}
    //};

    //}

    //class test
    // {
    // static void Main()
    // {
    // Person[] myPersons = new Person[2];
    // myPersons[0] = new Person { FirstName = "Ayrton", LastName = "Senna" };
    // myPersons[1] = new Person { FirstName = "Michael", LastName = "Schumacher" };
    // }

    // }

    锯齿数组:

    就是一个数组里面还有数组

    class JaggedArray
    {
    //public JaggedArray(){
    // int[][] a = new int[3][];
    // a[0] = new int[3];
    // }
    static void Main() {
    int[][] a = new int[3][];
    a[0] = new int[3];
    a[1] = new int[4];
    int[][] b = new int[2][] { new int[] { 1,2, 3 }, new int[] { 4, 5, 6 } };
    int[][] c = { new int[3] { 1, 2, 3 },new int[4] { 4,5,6,7} };
    for (int i = 0; i < b.Length; i++)
    {
    for (int j = 0; j < b[i].Length; j++)
    {
    Console.WriteLine(b[i][j]);
    }
    }
    Console.WriteLine("-----------");
    foreach (int []i in c)
    {
    foreach(int j in i)
    {
    Console.WriteLine(j);
    }
    }
    Console.Read();

    }

    }

    使用双层循环来迭代数组,第一层用来循环数组的每一行,第二层用来循环数组里面的数

    详见:https://www.cnblogs.com/afei-24/p/6738128.html

  • 相关阅读:
    Permission denied (publickey). fatal: Could not read from remote repository.
    jQuery OCUpload一键上传文件
    org.apache.subversion.javahl.ClientException: Working copy is not up-to-date
    测开之路一百三十五:实现登录身份验证功能
    测开之路一百三十四:实现指定查找功能
    测开之路一百三十三:实现sql函数封装
    测开之路一百三十二:实现修改功能
    测开之路一百三十一:实现删除功能
    测开之路一百三十:实现前端到数据库交互(增和查)
    测开之路一百二十九:jinja2模板语法
  • 原文地址:https://www.cnblogs.com/javazyh/p/9559795.html
Copyright © 2020-2023  润新知