Use MemoryStream and BinaryWriter to convert decimal to byte array : Memory Stream « File Stream « C# / C Sharp
- C# / C Sharp
- File Stream
- Memory Stream
Use MemoryStream and BinaryWriter to convert decimal to byte array

using System;
using System.IO;
class Test {
// Create a byte array from a decimal.
public static byte[] DecimalToByteArray (decimal src) {
using (MemoryStream stream = new MemoryStream()) {
using (BinaryWriter writer = new BinaryWriter(stream)){
writer.Write(src);
return stream.ToArray();
}
}
}
public static void Main() {
byte[] b = DecimalToByteArray(285998345545.563846696m);
// Convert a decimal to a byte array and display.
Console.WriteLine(BitConverter.ToString(b));
}
}
Related examples in the same category