C# 数据类型转换

1.byte[]转换为string

 string RecStartFrameStr = System.Text.Encoding.Default.GetString(MainForm.readData);

2.string转换为byte[]

 string strFileName;

 byte[] byteFileName = Encoding.ASCII.GetBytes(strFileName);

3.int转换为byte[]

 int PerFrameCnt = 0;

 byte[] DataFrame = new byte[1029];

 DataFrame[1] = (byte)PerFrameCnt;

 DataFrame[2] = (byte)~PerFrameCnt;           //取反

4.byte[]转int

 byte[] k = {12,13,14};

 int m = System.BitConverter.ToInt32(k,0);

5.int转string

 int a = 2023;

 string s1 = a.ToString(s);

 string s2 = Convert.ToString(a);

6.string 转int

 string s = "2023"

 int a = int.Parse(s);

 int b = 0;

 int.TryParse(s, out b);

 int c = Convert.ToInt32(s);

7.txtBattVol.Text转为double

string strBatVol = txtBattVol.Text;
double dlBatVol = double.Parse(strBatVol);

//第一种转换方法
 double p1 = double.Parse(strBatVol );
 //第二种转换方法
 double p2= Convert.ToDouble(strBatVol );

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值