'Intellisense warning "Expression is always false" after modulo operation
Consider this simple method that should round up a value to the next multiple of align:
private long RoundUp(long offset, long align)
{
long evenBy = offset % align;
if (evenBy == 0) // This line is underlined and Visual Studio means "Expression is always false"
{
return offset;
}
offset += (align - evenBy);
return offset;
}
The if statement is underlined and Visual Studio (2022) claims that the expression is always false. I can confirm with the debugger that both cases are followed in this test method:
[Fact]
public void TestRounding()
{
Assert.Equal(1024, RoundUp(1024, 1024));
Assert.Equal(1024, RoundUp(100, 1024));
}
What is the cause for this warning?
Edit: Here's a screenshot. No error code is given, unfortunately.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

