一、锯齿型数组的使用
1using System;
2
3public class JaggedArray
4{
5 public static void Main()
6 {
7 // 声明一个锯齿型数组,该数组有两个元素
8 int[][] array = new int[2][];
9
10 // 其中第一个元素是一个含有五个元素的数组
11 // 初始化array[0]
12 array[0] = new int[5] {1,3,5,7,9};
13
14
15 // 其中第二个元素是一个含有4个元素的数组
16 // 初始化array[1]
17 array[1] = new int[4] {0, 2, 4, 6};
18
19 // 逐一打印出数组的数组中所有的元素
20 for (int i=0; i < array.Length; i++)
21 {
22 Console.Write("第({0})个数组: ", i);
23
24 // 打印一维数组中的元素
25 for (int j=0; j < array[i].Length; j++)
26 {
27 Console.Write("{0} ", array[i][j]);
28 }
29 Console.WriteLine();
30 }
31 Console.Read();
32 }
33}
2
3public class JaggedArray
4{
5 public static void Main()
6 {
7 // 声明一个锯齿型数组,该数组有两个元素
8 int[][] array = new int[2][];
9
10 // 其中第一个元素是一个含有五个元素的数组
11 // 初始化array[0]
12 array[0] = new int[5] {1,3,5,7,9};
13
14
15 // 其中第二个元素是一个含有4个元素的数组
16 // 初始化array[1]
17 array[1] = new int[4] {0, 2, 4, 6};
18
19 // 逐一打印出数组的数组中所有的元素
20 for (int i=0; i < array.Length; i++)
21 {
22 Console.Write("第({0})个数组: ", i);
23
24 // 打印一维数组中的元素
25 for (int j=0; j < array[i].Length; j++)
26 {
27 Console.Write("{0} ", array[i][j]);
28 }
29 Console.WriteLine();
30 }
31 Console.Read();
32 }
33}
二、对负数取模的方法:
1、先化为正数模除,结果值与被模除数同号;
2、对负数取模的结果在不同的编译器可能有不同的结果。用%运算的时候,首先是尧两边都是整数,a%b等同于a-(a/b)*b。在VC6和BCB6里,结果的正负号与a相同,例如:-4%6=-1,4%6=4,4%-6=4,-4%-6=-4。