C# BinaryWriter Write(Single)
Description
BinaryWriter Write(Single)
Writes a four-byte floating-point
value to the current stream and advances the stream position by four bytes.
Syntax
BinaryWriter.Write(Single)
has the following syntax.
public virtual void Write(
float value
)
Parameters
BinaryWriter.Write(Single)
has the following parameters.
value
- The four-byte floating-point value to write.
Returns
BinaryWriter.Write(Single)
method returns
Example
//from w w w. ja v a 2s.c om
using System;
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((Single)2);
}
using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
{
Console.WriteLine(reader.ReadSingle());
}
}
}
The code above generates the following result.