put two shorts to a byte array
<p>I need a byte array with 4 bytes which contains 2 shorts. I have now this:</p>

<pre><code>MemoryStream str = new MemoryStream();
using (BinaryWriter writer = new BinaryWriter(stream)) {
     writer.Write((short) printscreen.Width);
     writer.Write((short) printscreen.Height);
}
byte[] bytes = str.ToArray();
</code></pre>

<p>In java I used bytebuffer. But what should I use for c#?</p>

<p>I send this bytes through a socket to a java server. Java code:</p>

<pre><code>byte[] data = new byte[in.available()];
in.read(data);
ByteBuffer buffer = ByteBuffer.wrap(data);
System.out.println(buffer.getShort());
</code></pre>
