Will this line of C# Compile?

object value = 1 / 0.0;

Will it throw an exception at run-time? If not what value will value have after this line has run? Kudos to those who didn’t need to check.

Comments

Chris
Ooh that’s interesting - how about -1 / 0.0 ? :-)

Chris
15/03/2007 4:10:00 PM
Dave
My wife says it will so there! She also says it will give you a divide by zero error at run time.

To add an opposing view, my cat thinks it wont compile.
16/03/2007 10:55:00 AM
Omer van Kloeten
If I remember my specs correctly, ‘value’ will have a boxed NaN value.

I think I recall a PositiveInfinity and NegativeInfinity in Int32, but that’s a longshot.
16/03/2007 11:29:00 AM
Eddie
Dang, I hate these "interview" pop quizes. I’m gonna throw a guess and I say it will compile but will throw an exception at run time.
16/03/2007 3:19:00 PM
Omer van Kloeten
Forgot to add that if it’s an unchecked statement (or unchecked project), an Exception will be thrown, although I’m not sure it would even compile…
17/03/2007 5:38:00 AM
tim w
It will not compile since value is a reserved word, right?
4/04/2007 11:34:00 AM