c# - Int vs Double and divide by zero exception -


we compile time error when integer divided 0 whereas in case of double there no compilation error @ run-time infinity/nan result. idea why int & double have different behavior when comes divide 0 exception?

void main() {     int number = 20;     var result1 = number/0; // divide 0 compile time exception      double doublenumber = 20;     var result2 = doublenumber/0.0; // no compile time error. result infinity or nan } 

because that's how it's defined. whereas integers there no special values infinity , nan, compiler throws error if can spot problem @ compile time.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -