c# - Is there a safe check I can do before calling DateTime.AddMonths(int months)? -


If I call the object using an int which is too large, at any date, Concerned humble message that says,

"The value of the added or subtracted value is at the time of an unrestricted date." Name of the parameter: months "

What should be examined on the logic of months?

From

:

logicoffference exception

The result is a datetime or less.

-or -

Months less than -120,000 or greater than 120,000.

Based on your comment, I would say that the value of the resulting month is more than 120,000.

You can get the total month at the time of the current date and can check that plus your value is not out of bounds, or others have suggested as an exception.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -