locked
C# Rookie needing help RRS feed

  • Question

  • I am taking a C# class in college, and I have to write a program using a double and a decimal. The double and the decimal have to have the same value, and the decimal needs to get an error message saying the value is out of range, but is still able to compile.

    I cannot figure this out to save my life. Any help would be appreciated.

    Tuesday, September 16, 2008 3:44 PM

Answers

  • Generate an error message, huh.  I assume that an attempt to assign the double and decimal the same value is supposed to occur at some point, when the value is out of range then you need to create a message and not cause an exception.  Well, think it through one step at a time.

    How would you know when the value being assigned to a value type is out of range?  Is there something existing that can programmatically tell you what the maximum or minimum value of value type can or could be?  

    When would be the best time to check if the assigned value is out of range? Before or after you try to assign the value?

    If an exception did occur---and it is a poor programming practice to intentionally cause exceptions---what could you possibly do to detect or catch the event?  

    If you detect the exception---before or after it occurs---what needs to be done? Display a message? What should happen after you display a message?
    Tuesday, September 16, 2008 4:37 PM