//学习内存流的读与写操作
class Program
{
static void Main(string[] args)
{
//创建固定大小的内存流,
byte[] b1=new byte[3];
MemoryStream mems = new MemoryStream(b1);
//准备要写入到memorystream底层的字节数组b1的数据
byte[] wr1 = new byte[3] { 1,2,3};
//通过内存流把wr1字节数组的值写入到b1字节数组中
mems.Write(wr1,0,3);
Console.WriteLine(mems.Capacity.ToString());
Console.WriteLine(mems.Length.ToString());
Console.WriteLine(mems.Position.ToString());
Console.WriteLine("向内存流写入数据操作完成");
mems.Close();
Console.WriteLine();
MemoryStream mems1 = new MemoryStream(b1);
//设置当前内存流的位置为开头
mems1.Seek(0,SeekOrigin.Begin);
long curp = mems1.Position;
//Console.WriteLine(curp.ToString());
while (curp
{
Console.WriteLine(mems1.ReadByte());
curp++;
}
Console.WriteLine("自内存流读取数据完毕");
}
}