We are writing a chat application. My friend is doing the server. And for the server to read my message, i have to send the message in bytes with the first 1 byte being the message type and the second 4 bytes being the message length. In Java there is an option to do something like this: ByteArray.allocate(4).putInt(length). Is there anything equivalent to it in c#?
What I have tried:
static byte[] DecimalToByteArray(decimal src)
{
using (MemoryStream stream = new MemoryStream(4))
{
using (BinaryWriter writer = new BinaryWriter(stream))
{
writer.Write(src);
return stream.ToArray();
}
}
}