追着嘟嘟学c#系列入门第十四篇-----c#的二维数组【蓝鸥出品】

来源:互联网 发布:不属于淘宝网禁售商品 编辑:程序博客网 时间:2024/05/17 02:11

二维数组


// 声明一个二维数组
// 生成一个2行3列的数组
// int [,] intArray=new int[2,3];
// 使用循环遍历数组
// 遍历数组中的每一行
// for (int i = 0; i < 2; i++) {
// for (int j = 0; j < 3; j++) {
// // 依次遍历每一行中的每一列
// Console.Write (intArray[i,j]);
// }
// Console.WriteLine ();
// }
// foreach遍历某个数组中的每个元素,
// 当我们不需要对循环本身进行控制,只需要关注数组中的每个元素的时候用
// foreach(int num in intArray){
// Console.WriteLine (num);
// }

练习:


1.

// int [,] a= new int[3,4] ;
// for (int i = 0; i < 3; i++) {
// for (int j = 0; j < 4; j++) {
// a [i, j] = i + j;
// }
// }
// //int [] temp = new int[1,1];
// int x=0, y = 0;
// int min= a[0,0];
// int max= a[0,0];
// for (int i = 0; i < 3; i++) {
// for (int j = 0; j < 4; j++) {
// Console.Write (a[i,j]);
// if (min < a [i, j]) {
//
// } else {
// min = a [i, j];
//
// }
// if (max > a [i, j]) {
//
// } else {
// max = a [i, j];
// x = i+1;
// y = j+1;
// }
// }
// Console.WriteLine ();
//
// }
// Console.WriteLine (min);
// Console.WriteLine (max);
// Console.WriteLine (x);
// Console.WriteLine (y);

2.

// int [,] temp1= new int[2,3];
//
// int [,] temp2= new int[3,2];
// for (int i = 0; i < 2; i++) {
// for (int j = 0; j < 3; j++) {
// temp2 [j, i] = temp1[i, j];
// }
// }

3.

int[] intArray = { 1, 2, 3, 4, 5};
int ji = 1;
foreach (int  item in intArray) {


ji = ji * item;
}
Console.WriteLine (ji);


链接:http://edu.csdn.net/course/detail/1982/30932?auto_start=1

0 0
原创粉丝点击