Java ByteBuffer closest counterpart in C #?

Currently looking for Java interface and C # application. In Java, I can use getShort() , getFloat() , etc. To get various types of data from the buffer.

In C #, I use a MemoryStream , but there is only one get() function. Does anyone know a data type or even a class that mimics this functionality?

+6
source share
2 answers

You can wrap a MemoryStream in a BinaryReader :

 using(var reader = new BinaryReader(yourStream)) { int someInt = reader.ReadInt32(); } 

BinaryReader can be found in the System.IO namespace.

For more information on the methods you can use, see MSDN . Keep in mind that methods follow the Read + CLR pattern. So, ReadInt32() for int, ReadUInt16() for short, etc.

+3
source

You are looking for a BinaryReader class that can read from any stream.

You can also use BitConverter , which works directly on byte arrays.

+3
source

All Articles