标签:creat array nbsp 元素 create 类型 write 打印 ++
1 int[] test1; //定义一个新数组 2 test1 = new int[10]; //定义数组长度(此时所有元素都是0) 3 4 int[] test2 = new int[] { 1, 2, 3, 4, 5, 6 }; //也可以直接定义元素 5 6 int[,] test3 = new int[3, 4]; //定义多维数组 7 8 int[][] test4 = new int[9][]; //定义交错数组
1 int[] intArry = Array.CreateInstance(typeof(int), 10) as int[]; //(类型,长度)
1 //(原数组,原数组开始拷贝索引,新数组,新数组开始拷贝索引,拷贝元素个数) 2 Array.Copy(intArry, 3, intArry2, 4, intArry.Length-4); //数组的拷贝
1 int[,] test2 = new int[9, 9]; //二维数组 2 for (int i = 1;i <= test2.GetLength(0); i++) //Getlength(维度)取高维数组中某维度的长度 3 { 4 for(int j =1;j<=i;j++) 5 { 6 7 test2[i - 1, j - 1] = i * j; 8 Console.Write(test2[i - 1, j - 1]);//不换行打印 9 } 10 Console.WriteLine();//换行打印 11 }
1 int[][] test1 = new int[9][]; //交错数组 2 3 for (int i =1;i<10;i++) 4 { 5 test1[i - 1] = new int[i]; //把每行的列数组定义为[0,0,0,0,0,0]这种 6 for (int j = 1;j<=i;j++) 7 { 8 test1[i-1][j-1]= i * j; //把每行的[0,0,0,0,0]这种列数组重新复制 9 10 Console.Write(test1[i - 1][j - 1]); 11 } 12 Console.WriteLine(); 13 }
标签:creat array nbsp 元素 create 类型 write 打印 ++
原文地址:https://www.cnblogs.com/xt112233/p/9698935.html