2014-07-13 34 views
-1

我想我已經絆倒了VS2012中的一個bug。DateTime的ArgumentOutOfRangeException

有沒有人看到以下不能成爲一個錯誤?

Public ReadOnly Property Email_DateTimeSent(ByVal uIndex As Integer) As DateTime 
    Get 

     If uIndex < _emails.Count Or uIndex < 0 Then 
      Stop'this line is not reached, so the index is valid 
     End If 

     Return _emails(uIndex).EMail_DateTimeSent 

    End Get 
End Property 

錯誤是「ArgumentOfRangeException:索引可能不是負面的,也不會小於列表。」

然而,當我將鼠標懸停在線路

  Return _emails(uIndex).EMail_DateTimeSent, 

我看到該值是有效的,也沒有超出範圍: _emails(uInde​​x).EMail_DateTimeSent =#7的/ 12/2014年2:19 :23 AM#

有沒有人看到這會導致錯誤?

謝謝!

+1

如果uInde​​x爲5且Count爲6,如果uInde​​x爲7且Count爲6,會發生什麼情況? –

+1

_emails是什麼?它看起來像它必須是一個具有屬性.EMail_DateTimeSent的類的列表 – dbasnett

回答

1

,以驗證該指數應該尋找小於零,或大於或等於的計數值的條件:

If uIndex >= _emails.Count Or uIndex < 0 Then 

在當前的代碼,只有這樣,才能達到Return聲明應提供大於或等於計數的索引,即在列表外部(或等待調試器在Stop語句處停止,然後繼續執行)。

相關問題