我有以下 C++ 行:
if(fromPos.x == 0xFFFF){
if(fromPos.y & 0x40){
fromIndex = static_cast<uint8_t>(fromPos.z);
}
else{
fromIndex = static_cast<uint8_t>(fromPos.y);
}
}
else
fromIndex = fromStackPos;
但我不知道如何在 C# 中使用 fromPos.y 和 0x40,按照 C++ 中的方式在 CSharp 上不起作用
最佳答案
在 C++ 中,if
语句中的条件不一定是 bool 表达式 - 但在 C# 中确实如此。您只需要检查结果是否为非零:
if ((fromPos.y & 0x40) != 0)
(由于优先级,括号是必需的;!=
比 &
绑定(bind)更紧密。)
关于C# 在 C++ 中对 (number & number) 的正确用法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26448271/