C# MemoryStream ReadByte

Description

MemoryStream ReadByte Reads a byte from the current stream.

Syntax

MemoryStream.ReadByte has the following syntax.


public override int ReadByte()

Returns

MemoryStream.ReadByte method returns The byte cast to a Int32, or -1 if the end of the stream has been reached.

Example

Read the remaining bytes, byte by byte.


//from   w w  w .j av a 2  s  . com


using System.IO;
using System;
public class MainClass
{
    public static void Main(String[] argv)
    {
        MemoryStream memStream = new MemoryStream();
        System.Console.WriteLine(memStream.CanRead);
        int count = 10;
        while (count < memStream.Length)
        {
            Console.WriteLine(Convert.ToByte(memStream.ReadByte()));
        }
    }
}

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