Stream.Read reads a sequence of bytes and advances the position
using System;
using System.IO;
public class Block
{
public static void Main()
{
Stream s = new MemoryStream();
for (byte i = 0; i < 10; i++)
{
s.WriteByte(i);
}
s.Position = 0;
byte[] bytes = new byte[s.Length];
int numBytesToRead = (int) s.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
int n = s.Read(bytes, numBytesRead, 10);
if (n == 0)
{
break;
}
numBytesRead += n;
numBytesToRead -= n;
}
s.Close();
Console.WriteLine("number of bytes read: {0:d}", numBytesRead);
}
}
Related examples in the same category