title: MemoryStream from bytes array with different types of data
body: <p>I want to create a memory stream which contains int32, int16, single values. Using binarywriter is useless so i tried to make bytes array. Because values are in different types, I don't know how to do it properly. So I try do like that: </p>
  
  <p><code>byte[] tab = new byte[]{2,0,0,0,3,0,3,0}</code> - 2 is int32 (four bytes), another two 3 are int16 (two bytes)</p>
  
  <p>that works fine, but when i want to add some single values, it generates errors. I cant do like that : </p>
  
  <p><code>byte[] tab = new byte[]{2,0,0,0,3,0,3,0,4.4f,5.6f}</code></p>
  
  <p>I must have stream in proper format, cause that stream will be read in this method : </p>
  
  <pre><code>short[] rawData;
   float[] modulusData;
     public void rawData(Stream s)
          {
  
              BinaryReader br = new BinaryReader(s);
  
              int dataCount = br.ReadInt32();
  
              if (dataCount &gt; 0)
              {
                  rawData = new short[dataCount];
                  for (int i = 0; i &lt; dataCount; i++)
                      rawData[i] = br.ReadInt16();
              }
              else
                  rawData = new short[0];
  
              dataCount = br.ReadInt32();
  
              if (dataCount &gt; 0)
              {
                  modulusData = new float[dataCount];
                  for (int i = 0; i &lt; dataCount; i++)
                      modulusData[i] = br.ReadSingle();
              }
              else
                  modulusData = new float[0];
          }
  </code></pre>
  
  <p>Anybody has idea how to do that ??</p>