2011-02-28 159 views
0

異常消息返回:我該如何解決這種異常? ArgumentOutOfRangeException

年,月,日和參數 描述一個未表示的日期時間。

例外打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了未處理 消息=年,月,日和參數描述的未表示的日期時間。 源= mscorlib程序 堆棧跟蹤: 在System.DateTime.DateToTicks(的Int32年的Int32月的Int32日) 在System.DateTime..ctor(的Int32年的Int32月的Int32日) 在TestGetDates.Program.Main(字符串[] args)在C:\ Documents and Settings \ ngd11 \ My Documents \ Visual Studio 2010 \ Projects \ TestGetDates \ TestGetDates \ Program.cs:行15 at System.AppDomain._nExecuteAssembly(Assembly assembly,String [] args) 在System.AppDomain.ExecuteAssembly(字符串assemblyFile,證據assemblySecurity,字串[] args) 在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在System.Threading.ThreadHelper.ThreadStart_Context(對象狀態) 在的System.Threading .ExecutionConte xt.Run(執行上下文的ExecutionContext,ContextCallback回調,對象狀態) 在System.Threading.ThreadHelper.ThreadStart() 的InnerException:

+0

僅供參考,使用自定義DateFormat(如「MM/yyyy」)時,在**本機Win32 DateTimePicker **中存在一個錯誤。 請參閱[這裏](http://connect.microsoft.com/VisualStudio/feedback/details/553375/system-argumentoutofrangeexception-year-month-and-day-parameters-describe-an-un-representable-datetime)描述。 並且有一個解決方法[這裏](http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/69b10b5b-a034-426e-a045-2bed8a1637a3) – itsho 2012-07-31 18:44:00

回答

2
date_tax.Day - index 

這可能是生產,是造成這種異常的負數,調試並檢查其價值。

+0

感謝您的回覆。我把那個改成了'AddDays(index)',但是另一個異常會發生,像是targetinvocationexception – Holyoxx 2011-02-28 05:18:02

+0

請提供更多的信息i-e 1.你想達到什麼目的? 2.例外Stacktrace(如果可以的話) – 2011-02-28 05:29:29

+0

沒關係。 :)我只是用了不同的方法:)謝謝反正 – Holyoxx 2011-02-28 05:42:37

相關問題