C# BinaryReader ReadChars

Description

BinaryReader ReadChars Reads the specified number of characters from the current stream, returns the data in a character array, and advances the current position in accordance with the Encoding used and the specific character being read from the stream.

Syntax

BinaryReader.ReadChars has the following syntax.


public virtual char[] ReadChars(
  int count
)

Parameters

BinaryReader.ReadChars has the following parameters.

  • count - The number of characters to read.

Returns

BinaryReader.ReadChars method returns

Example


using System;/*  www.j a  v  a2  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('c');
        }

        using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
        {
            char[] chars = new char[10];
            chars = reader.ReadChars(10);

        }
    }
}




















Home »
  C# Tutorial »
    System.IO »




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