声明并创建二维数组,并初始化为i系统的默认值
数组类型[,]数组名=new 数组类[m,n];
intp,]array2;
array2=new int[4,2]';
int [,]array2=new int[4,2];
C#当中的二维数组类型的标志是数组类型[,]不是C/C++当中的数组名[][]
创建二维·1数组并提供初始化值
数组类型[,]数组名=new 数组类型[,]{{....},{...},,....,{....}};
数组类型[,]数组名=[,]{{,,,,,},{,,,,,},,,,,{,,,,}};
创建成绩的二维数组score
int[,]score=new int[3,5]{{86,92,78,99,87},{78,87,80,77},{79,80,87,67,89}};
int[,]score=new int[,]{{86,92,78,99},78,87,80,77},{79,80,87,67,89};
int[,]score={{86,92,78,99,87},{78,87,80,77},{79,80,87,67,89}};
三维数组
int[,,]array3new int[4,2,3];
交错数组
是指数组元素为数组的数组
交错数组当中每个元素所表示的数组其长度可以不同
int[][]japArray=new int[3][];
jagArray[0]=new int[5];
jagArray[1]=new int[4];
jagArray[2]=new int[2];
int[][]jagArray=new int[][]{new int7[]{1,2,5,7,9},new int[]【0,2,4,6},new int[]{11,22}};
const int M=3,N=4;
static void main(String[]args){
int[,]a=new int[,]{{1,2,3,4,5},{4,5,6,8},{9,10,11,12}};
int[,]b=new int[,]{{1,4,7,10},2,5,8,11},{3,6,9,12}};
int[c,]=new int[M,N];
for(int i=0;i<M;i++)
for(int j=0;j<N;j++)
c[i,j]=a[i,j]+b[i,j];
Console.WriteLine("结果矩阵式");
for(int i=0;i<c.GetLength(0);i++)
{
for(int j=0;j<c.GetLength(1);j++)
Console.Write("{0,4}",c[i,j]);
Console.WriteLine();
}}}