And if speed is a factor:
unsafe static byte[] GetBytes(UInt64 value)
{
byte[] bytes = new byte[8];
fixed(byte* b = bytes)
*((UInt64*)b) = value;
return bytes;
}
The BitConverter version has a couple layers of indirection, so its
about 3 times slower (GetBytes(value)>GetUInt64Bytes(value)>internal
runtime call). It's strange, they sometimes do internal calls (for
Integral types) and sometimes they write their own (for floating-point
types).
Austin
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.