title: What is "ByteArray.uncompress()" in AS3 equivalent to in C#?
body: <p>I am trying to convert a AS3 (ActionScript 3) function to C#.</p>
  
  <p>This ActionScript function contains a class called ByteArray which from what I am aware of it's basically what it sounds like lmao. I think it's kind of similar of how byte[] would be in C#. Anyway, I have tried my best to convert the code to C# using MemoryStream and then writing bytes to it, and then returning UTF8 string as you can see in my code below. However, I feel as if my way of doing how the ActionScript code does isn't accurate and that is where my question above comes in.</p>
  
  <p>With them negative numbers being written into "loc1" (The ByteArray) and "loc1.uncompress()", that's where I feel like I am failing and was wondering if someone could help me out in converting this function so it's fully accurate?</p>
  
  <p>On top of that question, I would also like to ask if what I was doing with the negative numbers was correct in my C# code just like how the ActionScript code was doing it? Would mean a lot (:</p>
  
  <p>(Sorry if not fully understandable and if what I say doesn't match up as much)</p>
  
  <p>ActionScript Code:</p>
  
  <pre><code>private function p() : String
        {
           var _loc1_:ByteArray = new ByteArray();
           _loc1_.writeByte(120);
           _loc1_.writeByte(-38);
           _loc1_.writeByte(99);
           _loc1_.writeByte(16);
           _loc1_.writeByte(12);
           _loc1_.writeByte(51);
           _loc1_.writeByte(41);
           _loc1_.writeByte(-118);
           _loc1_.writeByte(12);
           _loc1_.writeByte(50);
           _loc1_.writeByte(81);
           _loc1_.writeByte(73);
           _loc1_.writeByte(49);
           _loc1_.writeByte(-56);
           _loc1_.writeByte(13);
           _loc1_.writeByte(48);
           _loc1_.writeByte(54);
           _loc1_.writeByte(54);
           _loc1_.writeByte(14);
           _loc1_.writeByte(48);
           _loc1_.writeByte(46);
           _loc1_.writeByte(2);
           _loc1_.writeByte(0);
           _loc1_.writeByte(45);
           _loc1_.writeByte(-30);
           _loc1_.writeByte(4);
           _loc1_.writeByte(-16);
           _loc1_.uncompress();
           _loc1_.position = 0;
           return _loc1_.readUTF();
        }
  </code></pre>
  
  <p>My C# Code:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public string p()
          {
              MemoryStream loc1 = new MemoryStream();
              loc1.WriteByte((byte)120);
              loc1.WriteByte((byte)~-38);
              loc1.WriteByte((byte)99);
              loc1.WriteByte((byte)16);
              loc1.WriteByte((byte)12);
              loc1.WriteByte((byte)51);
              loc1.WriteByte((byte)41);
              loc1.WriteByte((byte)~-118);
              loc1.WriteByte((byte)12);
              loc1.WriteByte((byte)50);
              loc1.WriteByte((byte)81);
              loc1.WriteByte((byte)73);
              loc1.WriteByte((byte)49);
              loc1.WriteByte((byte)~-56);
              loc1.WriteByte((byte)13);
              loc1.WriteByte((byte)48);
              loc1.WriteByte((byte)54);
              loc1.WriteByte((byte)54);
              loc1.WriteByte((byte)14);
              loc1.WriteByte((byte)48);
              loc1.WriteByte((byte)46);
              loc1.WriteByte((byte)2);
              loc1.WriteByte((byte)0);
              loc1.WriteByte((byte)45);
              loc1.WriteByte((byte)~-30);
              loc1.WriteByte((byte)4);
              loc1.WriteByte((byte)~-16);
              loc1.Position = 0;
              return Encoding.UTF8.GetString(loc1.ToArray());
          }
  </code></pre>