JCooney.NET

Joseph Cooney's Weblog

My Links

Blog Stats

News

I work for:


see also:
Dominic Cooney
Patrick Cooney

Archives

Image Galleries

My GotDotNet Samples

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.

posted on Thursday, March 15, 2007 6:33 AM

Feedback

# re: Will this line of C# Compile? 3/15/2007 4:10 PM Chris

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

Chris

# re: Will this line of C# Compile? 3/16/2007 10:55 AM 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.

# re: Will this line of C# Compile? 3/16/2007 11:29 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.

# re: Will this line of C# Compile? 3/16/2007 3:19 PM 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.

# re: Will this line of C# Compile? 3/17/2007 5:38 AM 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...

# re: Will this line of C# Compile? 4/4/2007 11:34 AM tim w

It will not compile since value is a reserved word, right?

Title  
Name  
Url
Security Word (prevent comment spam)
Protected by FormShield
Comments