using System;
using System.Text;
using System.IO;

public class Program
{
   public static void Main(string[] args)
   {
      MemoryStream ms = new MemoryStream(100);
      UnicodeEncoding ue = new UnicodeEncoding();

      byte[] textout = ue.GetBytes("Text im Arbeitsspeicher");
      //Schreiben in den Arbeitsspeicher
      ms.Write(textout, 0, textout.Length);
      
      Console.WriteLine(ms.Capacity.ToString());
      Console.WriteLine(ms.Length.ToString());
      Console.WriteLine(ms.Position.ToString());

      ms.Seek(0, SeekOrigin.Begin);


      //Lesen vom Arbeitsspeicher
      byte[] textin = new byte[ms.Length]; //Auf Pos 0 setzen
      int bytes = 0;
      while (bytes < ms.Length)
      {
         textin[bytes++] = Convert.ToByte(ms.ReadByte());
      }

      Console.WriteLine(ue.GetString(textin));

      Console.ReadLine();
   }
}

