編譯器警告 (層級 3) CS0675

用於 sign-extend 運算元的位元 OR 運算子;請先考慮轉換為較小的不帶正負號類型

編譯器隱含擴大了變數並擴充其正負號,然後在位元 OR 運算中使用該結果值。 這可能會導致非預期的行為。

下列範例會產生 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, value contains -1 (0xffffffff_ffffffff)
      // try the following line instead  
      // long value = (((long)hi) << 32) | ((uint)lo);   // correct, value contains 8589934591 (0x00000001_ffffffff)
   }  
}