C#将数字转换成字节数组的方法
本文实例讲述了C#将数字转换成字节数组的方法。分享给大家供大家参考。具体实现方法如下:
下面的代码用到了MemoryStream和BinaryWriter
//Createabytearrayfromadecimal
publicstaticbyte[]DecimalToByteArray(decimalsrc){
//CreateaMemoryStreamasabuffertoholdthebinarydata
using(MemoryStreamstream=newMemoryStream()){
//CreateaBinaryWritertowritebinarydatatothestream
using(BinaryWriterwriter=newBinaryWriter(stream)){
//WritethedecimaltotheBinaryWriter/MemoryStream
writer.Write(src);
//Returnthebyterepresentationofthedecimal
returnstream.ToArray();
}
}
}
希望本文所述对大家的C#程序设计有所帮助。
热门推荐
2 祝福语简短古诗词
10 高考祝福语简短10字
11 信件告别祝福语大全简短
12 学院祝福语女生大全简短
13 英语简短祝福语给学生
14 空军大学开学祝福语简短
15 20岁简短生日祝福语
16 老师开工仪式祝福语简短
17 幼儿狗年祝福语大全简短
18 诗词送行祝福语大全简短