Given the following information
Public Enum Request As Byte
None = 0
Identity = 1
License = 2
End Enum
Protected mType As Communication.Request
mType = Communication.Request.Identity
Debug.Print (BitConverter.GetBytes(mType).Length.tostring)
2
Why does bitconverter report that mType is a length of 2. I would have thought that passing a Byte into BitConverter.GetBytes would just return the Byte.
I mean it’s no big deal because it’s only sending a very small block of data across a TCP Socket, but I’m just intrigued why it thinks it’s 2 bytes.
Because there is no overload for BitConverter.GetBytes(Byte b) (see msdn), the nearest available implicit overload is used, which in this case, returns a byte[2].
Using simple code:
Compiling this and using ildasm, we see that the method for an int16 (which is a short) is called:
This is also visible while hovering the method in Visual Studio (the selected overload gets shown in the tooltip)