【发布时间】:2016-02-13 14:07:17
【问题描述】:
我正在将代码从 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 是负数,那么我遇到了问题。
关于我应该如何解决问题的任何意见?
【问题讨论】:
-
您需要将 uint 显式转换为 int。但考虑到这可能会导致数据丢失。
标签: java c# int type-conversion uint