二维数组:string[,] arr=new string[3,3];
a) 赋值:arr[0,1]=”一行三列的同学:李四”;
b) 访问:ConsoleWriteLine(”arr[0,1]=”+arr[0,1]);
c) 获取所有元素个数:ConsoleWriteLine(”arr.Length=”+ arr.Length);
d) 获取行数:ConsoleWriteLine(”二维行数:”+ arr.GetLength(0));
e) 获取列数:ConsoleWriteLine(”二维列数:”+ arr.GetLength(1));
f) 遍历:几维数组就几层循环
for(int row=0;row<arr.GetLength(0);row++)
{
for(int col=0;col<arr.GetLength(1);col++)
{
ConsoleWriteLine(“arr[{0},{1}]={2}”,row,col,arr[row,col]);
}
}
|