事情是這樣的:測試空數組索引
object[] arrayText = new object[1];
if (arrayText[1] == null)
{
MessageBox.Show("Is null");
}
我們知道,將是空的,但它拋出一個異常,但我不想處理它在try/catch塊,因爲這嵌套在一個循環中,並嘗試/ catch會減慢它,也看起來不太好:
object[] arrayText = new object[1];
try
{
if (arrayText[1] == null)
{
}
}
catch (Exception ex)
{
MessageBox.Show("Is null");
}
謝謝你的建議!
我使用了這個答案的變體: if(i> = rawDataTables.Length || rawDataTables [i] .Rows.Count == 0) – Carlo 2009-05-28 20:10:24
順便說一句,謝謝! – Carlo 2009-05-28 20:20:24
不客氣......我假設你在評論中使用了「如果(我<=」在你的示例中,而不是「if(i> =」...;) – Lucero 2009-05-28 20:26:42