C# BinaryWriter Write(Boolean)
Description
BinaryWriter Write(Boolean)
Writes a one-byte Boolean
value to the current stream, with 0 representing false and 1 representing
true.
Syntax
BinaryWriter.Write(Boolean)
has the following syntax.
public virtual void Write(
bool value
)
Parameters
BinaryWriter.Write(Boolean)
has the following parameters.
value
- The Boolean value to write (0 or 1).
Returns
BinaryWriter.Write(Boolean)
method returns
Example
The following code example demonstrates how to store and retrieve application settings in a file.
using System;/*from w ww . ja va2s. 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(true);
}
using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
{
Console.WriteLine(reader.ReadBoolean());
}
}
}
The code above generates the following result.