BinaryWriter.Write Method (Char)
Writes a Unicode character 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.
Assembly: mscorlib (in mscorlib.dll)
Because of data formatting conflicts, using this method with the following encodings is not recommended:
For a list of common I/O tasks, see Common I/O Tasks.
Unicode surrogate characters must be written out as pairs together in the same call, not individually. If you require support for surrogate pairs in your application, consider using a character array and the Write method overload.
The following code example shows how to read and write data using memory as a backing store.
Imports System Imports System.IO Public Class BinaryRW Shared Sub Main() Dim i As Integer = 0 Dim invalidPathChars() As Char = Path.InvalidPathChars Dim memStream As new MemoryStream() Dim binWriter As New BinaryWriter(memStream) ' Write to memory. binWriter.Write("Invalid file path characters are: ") For i = 0 To invalidPathChars.Length - 1 binWriter.Write(invalidPathChars(i)) Next i ' Create the reader using the same MemoryStream ' as used with the writer. Dim binReader As New BinaryReader(memStream) ' Set Position to the beginning of the stream. memStream.Position = 0 ' Read the data from memory and write it to the console. Console.Write(binReader.ReadString()) Dim memoryData( _ CInt(memStream.Length - memStream.Position) - 1) As Char For i = 0 To memoryData.Length - 1 memoryData(i) = binReader.ReadChar() Next i Console.WriteLine(memoryData) End Sub End Class
Available since 4.5
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1