new BinaryReader(stream) : Binary Read Write : File Stream C# Source Code


Custom Search

C# Source Code » File Stream » Binary Read Write »

 

new BinaryReader(stream)








    
 

using System;
using System.IO;

class MainClass
{
    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 decimal ByteArrayToDecimal (byte[] src){
        using (MemoryStream stream = new MemoryStream(src)){
           using (BinaryReader reader = new BinaryReader(stream)){
              return reader.ReadDecimal();
           }
        }
    }
    public static void Main()
    {
        byte[] b = null;

        b = BitConverter.GetBytes(true);
        Console.WriteLine(BitConverter.ToString(b));

        Console.WriteLine(BitConverter.ToBoolean(b, 0));

        b = BitConverter.GetBytes(3678);
        Console.WriteLine(BitConverter.ToString(b));

        Console.WriteLine(BitConverter.ToInt32(b, 0));

        b = DecimalToByteArray(285998345545.563846696m);
        Console.WriteLine(BitConverter.ToString(b));

        Console.WriteLine(ByteArrayToDecimal(b));
    }
    
}    

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo File Stream
» Binary Read Write