C# BinaryReader ReadDecimal

Description

BinaryReader ReadDecimal Reads a decimal value from the current stream and advances the current position of the stream by sixteen bytes.

Syntax

BinaryReader.ReadDecimal has the following syntax.


public virtual decimal ReadDecimal()

Returns

BinaryReader.ReadDecimal method returns A decimal value read from the current stream.

Example


using System;/* ww w. j a  v a 2s .c om*/
using System.IO;

class ConsoleApplication
{
    const string fileName = "data.dat";

    static void Main()
    {

        using (BinaryWriter writer = new BinaryWriter(File.Open(fileName, FileMode.Create)))
        {
            writer.Write(1.2M);
        }

        using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
        {
            Console.WriteLine(reader.ReadDecimal());
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter