C#的数组

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,字符


            

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值