本文实例讲述了c#将数字转换成字节数组的方法。分享给大家供大家参考。具体实现方法如下:
下面的代码用到了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(); } } }
希望本文所述对大家的c#程序设计有所帮助。
您可能感兴趣的文章:
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!
网友评论