欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#將數(shù)字轉(zhuǎn)換成字節(jié)數(shù)組的方法

 更新時(shí)間:2015年04月04日 12:39:13   作者:令狐不聰  
這篇文章主要介紹了C#將數(shù)字轉(zhuǎn)換成字節(jié)數(shù)組的方法,涉及C#字符串操作的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了C#將數(shù)字轉(zhuǎn)換成字節(jié)數(shù)組的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

下面的代碼用到了MemoryStream 和 BinaryWriter

// Create a byte array from a decimal
public static byte[] DecimalToByteArray (decimal src) {
 // Create a MemoryStream as a buffer to hold the binary data
 using (MemoryStream stream = new MemoryStream()) {
  // Create a BinaryWriter to write binary data to the stream
  using (BinaryWriter writer = new BinaryWriter(stream)) {
   // Write the decimal to the BinaryWriter/MemoryStream
   writer.Write(src);
   // Return the byte representation of the decimal
   return stream.ToArray();
  }
 }
}

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論