MemoryStream.ToArray() : MemoryStream « System.IO « C# / C Sharp by API






MemoryStream.ToArray()

  

using System;
using System.IO;

public class MainClass
{
    public static int Main(string[] args)
    {
    MemoryStream myMemStream = new MemoryStream();
    myMemStream.Capacity = 256;

    for(int i = 0; i < 256; i++)
      myMemStream.WriteByte((byte)i);

    myMemStream.Position = 0;

    for(int i = 0; i < 256; i++)
      Console.Write(myMemStream.ReadByte());  
    Console.WriteLine();

    FileStream dumpFile = new FileStream("Dump.dat", FileMode.Create, FileAccess.ReadWrite);
    myMemStream.WriteTo(dumpFile);
    byte[] bytesinMemory = myMemStream.ToArray();
    myMemStream.Close();

    for(int i = 0; i < bytesinMemory.Length; i++)
      Console.Write(bytesinMemory[i]);

    return 0;
    }
}

   
    
  








Related examples in the same category

1.new MemoryStream()
2.MemoryStream.Capacity
3.MemoryStream.GetBuffer()
4.MemoryStream.Seek
5.MemoryStream.SetLength
6.MemoryStream.Write
7.MemoryStream.WriteLine