[C#] C#将数字转换成字节数组 →→→→→进入此内容的聊天室

来自 , 2021-02-07, 写在 C#, 查看 130 次.
URL http://www.code666.cn/view/dab10c50
  1. // Create a byte array from a decimal
  2. public static byte[] DecimalToByteArray (decimal src) {
  3.  
  4.     // Create a MemoryStream as a buffer to hold the binary data
  5.     using (MemoryStream stream = new MemoryStream()) {
  6.  
  7.         // Create a BinaryWriter to write binary data to the stream
  8.         using (BinaryWriter writer = new BinaryWriter(stream)) {
  9.  
  10.             // Write the decimal to the BinaryWriter/MemoryStream
  11.             writer.Write(src);
  12.  
  13.             // Return the byte representation of the decimal
  14.             return stream.ToArray();
  15.         }
  16.     }
  17. }
  18. //csharp/7767

回复 "C#将数字转换成字节数组"

这儿你可以回复上面这条便签

captcha