Compiler Warning (level 3) CS0675

按位“或”运算符在带符号扩展操作数上使用;请考虑首先强制转换为较小的无符号类型

编译器隐式地拓宽了并带符号扩展了变量,然后在按位“或”运算中使用了结果值。这可能导致意外的行为。

下面的示例生成 CS0675:

// CS0675.cs
// compile with: /W:3
using System;

public class sign
{
   public static void Main()
   {
      int hi = 1;
      int lo = 1;
      long value = (((long)hi) << 32) | lo;              // CS0675
      // try the following line instead
      // long value = (((long)hi) << 32) | ((uint)lo);   // correct
   }
}