异常消息返回:
年,月,日参数 描述一个不可表示的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。 来源= mscorlib程序 堆栈跟踪: 在System.DateTime.DateToTicks(Int32年,Int32月,Int32日) 在System.DateTime..ctor(Int32年,Int32月,Int32日) at 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 assembly,String [] args) 在System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args) 在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在System.Threading.ThreadHelper.ThreadStart_Context(对象状态) 在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态) 在System.Threading.ThreadHelper.ThreadStart() InnerException:
答案 0 :(得分:2)
date_tax.Day - index
这可能会产生一个负数,导致此异常,调试并检查其值。