0

异常消息返回:

Year、Month 和 Day 参数描述了不可表示的 DateTime。

异常命中monthCalendar1.SelectionStart

            DateTime check_date = monthCalendar1.SelectionStart;

            for (int index = 0; index <= 5; index++)
            {
                check_date = new DateTime(check_date.Year, check_date.Month, check_date.Day - index);

            }

我也试过这个。但是发生了另一个异常TargetInvocationException

                DateTime check_date = monthCalendar1.SelectionStart;

                for (int index = 0; index <= 5; index++)
                {
                    check_date = check_date.AddDays(-index);

                }

异常详情:

System.ArgumentOutOfRangeException 未处理 Message=Year、Month 和 Day 参数描述了无法表示的 DateTime。Source=mscorlib StackTrace:在 System.DateTime.DateToTicks(Int32 年,Int32 月,Int32 日)在 System.DateTime..ctor(Int32 年,Int32 月,Int32 日)在 TestGetDates.Program.Main(String[] args)在 C:\Documents and Settings\ngd11\My Documents\Visual Studio 2010\Projects\TestGetDates\TestGetDates\Program.cs:第 15 行 System.AppDomain._nExecuteAssembly(Assembly 程序集,String[] args) 在 System.AppDomain.ExecuteAssembly (String assemblyFile, Evidence assemblySecurity, String[] args) 在 System.Threading.ThreadHelper.ThreadStart_Context(Object state) 在 System.Threading.

4

1 回答 1

2
  date_tax.Day - index

这可能会产生导致此异常的负数,调试并检查其值。

于 2011-02-28T04:56:28.787 回答