How to Convert Decimal to byte array in C# ?

Below is a sample sourcecode that demonstrates how to Convert DEcimal to byte array in C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            MemoryStream memoryStream = new MemoryStream();
            BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
            double data = 255097.100;
            binaryWriter.Write(data);
            Console.WriteLine(BitConverter.ToString(memoryStream.ToArray()));
            Console.Read();
        }
    }
}
%d bloggers like this: