【问题标题】:reinterpret_cast in C#, migrate code from c++ to c# [duplicate]C# 中的 reinterpret_cast,将代码从 C++ 迁移到 C# [重复]
【发布时间】:2017-04-15 18:11:26
【问题描述】:

我想将以下c++代码迁移到c#

https://www.unknowncheats.me/forum/counterstrike-global-offensive/186820-cs-matchid-4.html

我的问题在这里, 我如何在 C# 中做到这一点

uint64_t matchid = *reinterpret_cast<uint64_t*>(result.data());
uint64_t outcomeId = *reinterpret_cast<uint64_t*>(result.data() + 8);
uint16_t tokenId = *reinterpret_cast<uint16_t*>(result.data() + 16);

结果一定是这样的

matchId: 3203527750019186923, 结果ID:3203531838828052697, 令牌ID:13431

谢谢

【问题讨论】:

    标签: c# c++


    【解决方案1】:

    在代码中有一个std::array&lt;char, 18&gt; result。在 C# 中,它将是 byte[] result

    所以:

    ulong matchId = BitConverter.ToUint64(result, 0);
    ulong outcomeId = BitConverter.ToUint64(result, 8);
    ulong tokenId = BitConverter.ToUint64(result, 16);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-23
      • 2011-02-09
      • 2014-03-22
      • 1970-01-01
      • 1970-01-01
      • 2012-02-27
      • 2017-10-31
      • 2014-04-24
      相关资源
      最近更新 更多