C#的数组定义格式如下:
写法1:
int[ ] a;
a = new int[5];
//或者写成一行
int[ ] a = new int[5];
//即a[0]到a[4]
写法2: int[ ] a = new int[ ]{1,2,3,4,5};
写法3: int[ ] a = new int[5]{1,2,3,4,5};
ps:1.字符串型数组的默认值为null,不是""!
2.string[ ] strA_1 = new string[3];
Response.Write(strA_1[0].Length);//输出空字符串的strA_1[0]的长度。
3.字符型数组的默认值为"",不是null,对应ACSII值为0
4.char[ ] ca = new char[3];
ca[0]='B';
Response.Write(Convert.ToInt32(ca[0]));//得到B对应的ASCII码值
5.数值型的数组,默认值为0;布尔型的数组,默认值为FALSE
6.日期时间型,默认值为公元1年1月1日,0点0分0秒
DateTime[ ] dtA = new DateTime[3];
Response.Write(dtA[0]);
7.string s;
s="hello world";
char[ ] c;//可以先不用定多少数目
c=s.ToCharArray();//字符串变为字符型数组
8.Response.Write(c.Length);//十分有用的方法,遍历函数,突然明白为什么要这样定义数组“char[ ] c”,这样方便后面对数组C进行各种操作,将数组C当作对象来处理。
9..char_a[1]=Convert.ToChar(Convert.ToInt16(char_a[1]+4);
//Convert.ToInt16()得到ASCII码值先,Convert.ToChar转换为字符
//char,英文是指character,字符