Code inspection: Constant shift expression with non-zero operands results in a zero value
Some constant shift expressions look meaningful but always evaluate to zero because all significant bits are shifted out. This inspection reports constant shift expressions with non-zero operands whose result is always zero.
Example
class Example
{
void Test()
{
var value = 1 << 40;
}
}
class Example
{
void Test()
{
var value = (long)1 << 40;
}
}
Quick-fix
If widening the left operand preserves the intended value, the quick-fix casts it to a wider type. In other cases, the right fix is usually to change the shift count or use a wider left operand explicitly.
01 April 2026