我发现.net框架中GetBytes
函数的实现类似于:
public unsafe static byte[] GetBytes(int value)
{
byte[] bytes = new byte[4];
fixed(byte* b = bytes)
*((int*)b) = value;
return bytes;
}
我不太确定我完全理解这两行的细节:
fixed(byte* b = bytes)
*((int*)b) = value;
有人可以在这里提供更详细的解释吗?我应该如何在标准C++中实现此函数?