What is equivalent to Java ByteBuffer.wrap in C #?

byte[] input = new byte[] {2, 4, 5, 2, 1}; ByteBuffer bytebuf = ByteBuffer.wrap(input); 

ByteBuffer.wrap(byte[] array) method makes the buffer and the array interconnected, changes in the buffer result in the array changing and vice versa.

The equivalent of ByteBuffer in C # is memystream. But I do not know how to connect memystream with array ByteBuffer.wrap() method.

Can anyone say what is equivalent to ByteBuffer.wrap() in C #? I searched everywhere, but could not find the answer at all.

Thanks in advance.

+4
source share
1 answer

Use binary writing and memory stream.

I did not put this question as a duplicate just because you did not ask exactly what this other poster did. I'm not sure what to do in this case, but still want to help you. Good luck

Here is the code from this link for posterity:

 MemoryStream stream = new MemoryStream(); using (BinaryWriter writer = new BinaryWriter(stream)) { writer.Write(myByte); writer.Write(myInt32); writer.Write("Hello"); } byte[] bytes = stream.ToArray(); 
+2
source

Source: https://habr.com/ru/post/1495164/


All Articles