using System;
int i = 123;
byte [] intBuff = BitConverter.GetBytes(i); // 将 int 转换成字节数组
lob.Write(intBuff, 0, 4);
i = BitConverter.ToInt32(intBuff, 0); // 从字节数组转换成 int
double x = 123.456;
byte [] doubleBuff = BitConverter.GetBytes(x); // 将 double 转换成字节数组
lob.Write(doubleBuff, 0, 8);
x = BitConverter.ToDouble(doubleBuff, 0); // 从字节数组转换成 double
int i = 123;
byte [] intBuff = BitConverter.GetBytes(i); // 将 int 转换成字节数组
lob.Write(intBuff, 0, 4);
i = BitConverter.ToInt32(intBuff, 0); // 从字节数组转换成 int
double x = 123.456;
byte [] doubleBuff = BitConverter.GetBytes(x); // 将 double 转换成字节数组
lob.Write(doubleBuff, 0, 8);
x = BitConverter.ToDouble(doubleBuff, 0); // 从字节数组转换成 double
本文深入探讨了在C#中使用字节流进行整数和浮点数的转换过程,通过实例展示了如何将整型和浮点型数据编码为字节数组,并在后续操作中将其解码回原始数据类型。
1342

被折叠的 条评论
为什么被折叠?



