using System;
using System.IO;
public class Block
{
public static void Main()
{
Stream s = new MemoryStream();
for (int i=0; i<100; i++)
s.WriteByte((byte)i);
s.Position = 0;
// Now read s into a byte buffer.
byte[] bytes = new byte[s.Length];
int numBytesToRead = (int) s.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
// Read may return anything from 0 to numBytesToRead.
int n = s.Read(bytes, numBytesRead, numBytesToRead);
// The end of the file is reached.
if (n==0)
break;
numBytesRead += n;
numBytesToRead -= n;
}
s.Close();
// numBytesToRead should be 0 now, and numBytesRead should
// equal 100.
Console.WriteLine("number of bytes read: "+numBytesRead);
}
}
using System.IO;
public class Block
{
public static void Main()
{
Stream s = new MemoryStream();
for (int i=0; i<100; i++)
s.WriteByte((byte)i);
s.Position = 0;
// Now read s into a byte buffer.
byte[] bytes = new byte[s.Length];
int numBytesToRead = (int) s.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
// Read may return anything from 0 to numBytesToRead.
int n = s.Read(bytes, numBytesRead, numBytesToRead);
// The end of the file is reached.
if (n==0)
break;
numBytesRead += n;
numBytesToRead -= n;
}
s.Close();
// numBytesToRead should be 0 now, and numBytesRead should
// equal 100.
Console.WriteLine("number of bytes read: "+numBytesRead);
}
}