【发布时间】:2015-03-27 20:56:16
【问题描述】:
我有一个“价格记录”列表。如果列表的大小大于 0,我想访问列表的最后一项。有时我的程序在想要访问列表的最后一项时崩溃,尽管列表的大小为 0。
在我看来,这种崩溃永远不会发生。请帮助我提出您的建议。
这是我的代码
JermLib.PriceListFull plNew = DownLoadSymbolHistoricalPrice(yTicker, dirPath, intStartDate, dgwErrorList);
.....
.....
if (plNew.record.Count > (int)0 )
{
if (plNew.record.Count < 1 ) { MessageBox.Show("PlNew Count < 1"); }
else { }
if (plNew.record.Count == 0) { MessageBox.Show("PlNew Count = 0"); }
else { }
// theese test never trigger
// It crashes at:
if (( intToday - plMS.record[plMS.record.Count - 1].date > 200 & intToday - plMS.record[plMS.record.Count - 1].date < 1000)
| intToday - plMS.record[plMS.record.Count - 1].date > 9100 )
//due to
//plMS.record.Count - 1 = -1 which is out of bounds
}
【问题讨论】:
-
欢迎来到 Stackoverflow! 1. 请通过拼写检查器运行您的问题。 2. 缩进你的代码并正确格式化。 3. 用您正在使用的编程语言标记问题。谢谢!
标签: list indexoutofboundsexception