将字节交换/转移代码片段从C++转换为.NET

asd*_*ael 0 c# c++

我在C++中有一个简短的代码片段,我需要在C#中具有相同的功能:

typedef enum {eD=0x0, eV=0x1, eVO=0x2, eVC=0x3} eIM;
#define htonl(x)  ( ( ( ( x ) & 0x000000ff ) << 24 ) | \
                    ( ( ( x ) & 0x0000ff00 ) << 8  ) | \
                    ( ( ( x ) & 0x00ff0000 ) >> 8  ) | \
                    ( ( ( x ) & 0xff000000 ) >> 24 ) )

int value = htonl(eV);
Run Code Online (Sandbox Code Playgroud)

不幸的是,我不是大程序员,所以我需要一些帮助.

Mar*_*k H 5

enum eIM { eD = 0, eV, eVO, eVC }
int value = System.Net.IPAddress.HostToNetworkOrder((int)eIM.eV);
Run Code Online (Sandbox Code Playgroud)