![](/img/trans.png)
[英]What is an IndexOutOfRangeException / ArgumentOutOfRangeException and how do I fix it?
[英]How can i fix this kind of exception? ArgumentOutOfRangeException
異常消息返回:
年,月和日參數描述了不可表示的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日)at System.DateTime..ctor(Int32 year,Int32 month,Int32 day)at TestGetDates.Program.Main(String [] args)在C:\\ Documents and Settings \\ ngd11 \\ My Documents \\ Visual Studio 2010 \\ Projects \\ TestGetDates \\ TestGetDates \\ Program.cs:System.AppDomain.ExecuteAssembly的System.AppDomain._nExecuteAssembly(Assembly assembly,String [] args)第15行(String assemblyFile,Evidence assemblySecurity,String [] args)在System.Threading.ExecutionContext.Run的System.Threading.ThreadHelper.ThreadStart_Context(Object state)中的Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()(ExecutionContext executionContext,ContextCallback callback) ,對象狀態)在System.Threading.ThreadHelper.ThreadStart()InnerException:
date_tax.Day - index
這可能會產生一個負數,導致此異常,調試並檢查其值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.