gpt4 book ai didi

c# - 编译器错误或误解?或者穿短裤的接线员

转载 作者:太空狗 更新时间:2023-10-29 23:13:44 31 4
gpt4 key购买 nike

<分区>

我有一行代码在 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 来消除警告/错误。

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com