Paw*_*hra 4 .net c# divide-by-zero
当整数除以零时,我们得到编译时错误;而在double的情况下,没有编译错误,但在运行时,我们得到无穷大/ NaN作为结果.知道为什么int和double在除零异常时会有不同的行为吗?
void Main()
{
int number = 20;
var result1 = number/0; // Divide by zero compile time exception
double doubleNumber = 20;
var result2 = doubleNumber/0.0; // no compile time error. Result is infinity or NaN
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5286 次 |
| 最近记录: |