When you use the modulus operator in the .NET Framework 3.5 or the .NET Framework 4.0, incorrect results are returned. Specifically, this issue occurs when you run the remainder operation and when you use certain 64-bit integer values under the x86 architecture.
The following sample code illustrates this problem:Here the output is 93 instead of the correct result of -7.
The following sample code illustrates this problem:
class Program
{
static void Main(string[] args)
{
DoModulo();
}
public static void DoModulo()
{
const int LNXBASE = 100;
long longX = -856480339907;
var mod = longX % LNXBASE;
Console.WriteLine(mod);
}
}