なぜこの代入はcomileエラーを生成するのですか?この場合Constant value '-2147483648' cannot be converted to a 'ulong'
に使用する必要がありますか?unchecked (...)
ulong xDummy30 = (1 << 30); // works
ulong xDummy31 = (1 << 31); // ERROR 25 Constant value '-2147483648' cannot be converted to a 'ulong'
ulong xDummy32 = (1 << 32); // works
代わりにこれを使用すると動作します:
ulong xDummy31a = unchecked((ulong)(1 << 31));
// or
ulong xDummy31b = (1ul << 31); // comment from Regis Portalez
質問を編集C# でビット演算を行うときに 0 (ゼロ) をキャストする必要があるのはなぜですか? 同様の答えがあり、観察された動作の理由は同じです。しかし、それらは異なる質問です。