Inconsistency in divide-by-zero behavior between different value types
问题 Please consider the following code and comments: Console.WriteLine(1 / 0); // will not compile, error: Division by constant zero int i = 0; Console.WriteLine(1 / i); // compiles, runs, throws: DivideByZeroException double d = 0; Console.WriteLine(1 / d); // compiles, runs, results in: Infinity I can understand the compiler actively checking for division by zero constant and the DivideByZeroException at runtime but: Why would using a double in a divide-by-zero return Infinity rather than