Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

MemoryStream.WriteByte Method

Writes a byte to the current stream at the current position.

[Visual Basic]
Overrides Public Sub WriteByte( _
   ByVal value As Byte _
)
[C#]
public override void WriteByte(
 byte value
);
[C++]
public: void WriteByte(
 unsigned char value
);
[JScript]
public override function WriteByte(
   value : Byte
);

Parameters

value
The byte to write.

Exceptions

Exception Type Condition
NotSupportedException The stream does not support writing. For additional information see CanWrite.

-or-

The current position is at the end of the stream, and the capacity cannot be modified.

ObjectDisposedException The current stream is closed.

Remarks

For an example of creating a file and writing text to a file, see Writing Text to a File. For an example of reading text from a file, see Reading Text from a File. For an example of reading from and writing to a binary file, see Reading and Writing to a Newly Created Data File.

This method overrides WriteByte.

Except for a MemoryStream constructed with a byte[] parameter, write operations at the end of a MemoryStream expand the MemoryStream.

Example

[Visual Basic, C#, C++] This code example is part of a larger example provided for the MemoryStream class.

[Visual Basic] 
' Write the second string to the stream, byte by byte.
count = 0
While(count < secondString.Length)
    memStream.WriteByte(secondString(count))
    count += 1
End While

[C#] 
// Write the second string to the stream, byte by byte.
count = 0;
while(count < secondString.Length)
{
    memStream.WriteByte(secondString[count++]);
}

[C++] 
// Write the second string to the stream, byte by byte.
count = 0;
while(count < secondString->Length)
{
    memStream->WriteByte(secondString[count++]);
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

MemoryStream Class | MemoryStream Members | System.IO Namespace | Working with I/O | Reading Text from a File | Writing Text to a File

Show:
© 2014 Microsoft