C# BinaryReader ReadSingle

Description

BinaryReader ReadSingle Reads a 4-byte floating point value from the current stream and advances the current position of the stream by four bytes.

Syntax

BinaryReader.ReadSingle has the following syntax.


public virtual float ReadSingle()

Returns

BinaryReader.ReadSingle method returns A 4-byte floating point value read from the current stream.

Example


using System;/*from   www.j  a  va2  s  .c o  m*/
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.0F);
        }
        using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
        {
            Console.WriteLine(reader.ReadSingle());
        }
    }
}

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