C# BinaryWriter Write(Char[]) Array

Description

BinaryWriter Write(Char[]) Writes a character array to the current stream and advances the current position of the stream in accordance with the Encoding used and the specific characters being written to the stream.

Syntax

BinaryWriter.Write(Char[]) has the following syntax.


public virtual void Write(
  char[] chars
)

Parameters

BinaryWriter.Write(Char[]) has the following parameters.

  • chars - A character array containing the data to write.

Returns

BinaryWriter.Write(Char[]) method returns

Example


using System;/*ww  w .  jav  a  2 s  . co  m*/
using System.IO;

class BinaryRW
{
    static void Main()
    {
        int i = 0;
        char[] myChars = new char[]{'a','b','c'};
        MemoryStream memStream = new MemoryStream();
        BinaryWriter binWriter = new BinaryWriter(memStream);

        binWriter.Write(myChars);

        BinaryReader binReader = new BinaryReader(memStream);

        memStream.Position = 0;

        Console.Write(binReader.ReadString());
        char[] memoryData = new char[memStream.Length - memStream.Position];
        for(i = 0; i < memoryData.Length; i++)
        {
            memoryData[i] = binReader.ReadChar();
        }
        Console.WriteLine(memoryData);
    }
}




















Home »
  C# Tutorial »
    System.IO »




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