c# - C++ 到 .NET : I need help with understanding C++ code to convert it to . NET

标签 c# .net c++ f#

C++代码是:

unsigned short* ui=(unsigned short*)&buf[110];
            CountDev=ui[0];

buf 是 byte[],CountDev 是 unsigned int

(BCB6 编译器 x86)

我的尝试是: F#

...CountDev  = System.BitConverter.ToInt32( [| arrayRead.[110]; arrayRead.[111] |] , 0 )

C#

...CountDev  = System.BitConverter.ToInt32( [arrayRead[110]; arrayRead[111]] , 0 )

但说真的,我不能确定。请检查我的尝试,如果我做错了请告诉我。

最佳答案

您可以使用:

  ... = System.BitConverter.ToUint16(arrayRead, 110);

但它确实取决于大/小端(数组中字节的顺序)。
您将需要该规范或良好的测试用例。

关于c# - C++ 到 .NET : I need help with understanding C++ code to convert it to . NET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7255457/

相关文章:

c# - 是否有不使用连续内存的开源 MemoryStream 实现?

c# - 如何将时间设置为当天的午夜?

c# - 如何获取 "System.Drawing.Image"的文件大小

c# - 性能/风格 : Changing an object by reference vs returning a copy in C#

c# - 如何让命名空间别名 operator::在 C# 下工作?

c++ - 我可以将 MPI 与共享内存一起使用吗

c# - 字符串清理和格式化

c# - weka .net ikvm -> 为什么加载 csv 文件这么慢?

c++ - Qt 和 OpenGL : change the state outside paintGL function

c# - 正确地将 C++ long 转换为 C# int