C# BinaryReader ReadBoolean

Description

BinaryReader ReadBoolean Reads a Boolean value from the current stream and advances the current position of the stream by one byte.

Syntax

BinaryReader.ReadBoolean has the following syntax.


public virtual bool ReadBoolean()

Returns

BinaryReader.ReadBoolean method returns true if the byte is nonzero; otherwise, false.

Example

The following code example demonstrates how to store and retrieve application settings in a file.


//  w w w. j  av  a  2s  .  co  m
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(true);
        }

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

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