作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
<分区>
我有一行代码在 VS2015 中给我一条警告消息 (CS0675),但在 2013 年却没有。
shortValue |= (short)anEnum;
Warning CS0675 Bitwise-or operator used on a sign-extended operand; consider casting to a smaller unsigned type first. The compiler implicitly widened and sign-extended a variable, and then used the resulting value in a bitwise OR operation. This can result in unexpected behavior.
很明显,枚举和 short 被扩展为 int,应用了 or 运算符,然后将结果分配给 short。
如果我将代码更改为 shortValue = shortValue | (short)anEnum;
我收到编译器错误 CS0266。但是按位或应该对短裤有效(我相信在这两种情况下)。如果我将鼠标悬停在 |
上,它显示为 int 运算符,我是否遗漏了什么或者我应该将其报告为错误?
PS:我知道我可以通过使用 =
而不是 |=
并将结果转换为 short 来消除警告/错误。
对不起我的英语不好,我来自意大利XD 我用一个简单的图形选择完成了 Frog 游戏:带有大量更新标签的网格布局。它工作得很好。我可以设置图标而不是标签,但现在我想更好地佩戴它,我的老师告诉我从 QGr
我是一名优秀的程序员,十分优秀!