我正在将代码从 java 转换为 c#,但遇到了 int 和 uint 的问题。 Java代码(摘录):
public static final int SCALE_PROTO4_TBL = 15;
public static final int [] sbc_proto_4 = { 0xec1f5e60 >> SCALE_PROTO4_TBL };
转换后的 C# 代码(摘录):
public const int SCALE_PROTO4_TBL = 15;
int[] sbc_proto_4 = new int[] { 0xec1f5e60 >> SCALE_PROTO4_TBL };
这会导致以下编译错误: 错误 CS0266 无法将类型“uint”隐式转换为“int”。存在显式转换(您是否缺少强制转换?)
存在很多类似上面的代码,但我不确定是否应该将所有 Java int 转换为 C# uint ?我记得 C# uint 不存储负值,如果 java int 是负数,那么我遇到了问题。
关于我应该如何解决这个问题有什么意见吗?
最佳答案
你可以这样尝试:
int[] sbc_proto_4 = new int[] { unchecked((int)0xec1f5e60) >> SCALE_PROTO4_TBL };
即,您必须显式转换 uint(0xec1f5e60)。
关于Java 到 C# 的转换 - int uint 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33668241/