Fork me on GitHub
 int[] a = new int[3];
            a[0] = 5;
            int[] a1 = { 1, 2, 3 };
            int[] a2 = new int[] { 1, 2 };
            int[] a3 = new int[3] { 1, 2,3 };
            int[] a5;
            a5=new int[5];


            //多维数组,数组两个数不能为空
            int [,] b=new int[3,4];
            int[,] b4;
            b4 = new int[2, 3];
            //int[,] b5=new int[3,];//错误
            b[0, 0] = 1;
            int [,] b1=new int[,]{{1,2},{2,3},{1,3}};
            b1[0, 0] = 6;
            int[,] b2 = { { 1, 2 }, { 2, 3 }, { 1, 3 } };
            int[,] b3 = new int[2, 3] { { 2, 3, 1 }, { 1, 2, 3 } };
            //int[,] b4 = new int[2, 3] { { 2, 3, 1 } };//错误


            //交错数组第一个不能为空,第二个必须为空
            int[][] c = new int[2][];
            int[][] c2;
            c2 = new int[2][];
            //交错数组可以使用数组直接赋值
            c2[0] = a1;
            c2[1][0] = 2;
            int [][] c1=new int[1][]{new int[]{1}};
           // int[][] c3 = new int[1][] { { 1 } };//错误
            //int [][] c1=new int[1][1]{new int[]{1}};//错误

 

posted on 2013-12-14 18:46  lingfeng95  阅读(261)  评论(0编辑  收藏  举报