我已經寫了一段代碼,我在下面分兩位小數。當代碼中z的值是2.33時,它工作正常,但是當代碼中z的值是2.0時,在這一行「long secondValue = Convert.ToInt64(values [1]);」它崩潰爲「索引數組的範圍之外」如何解決「索引超出數組邊界」?
result_lstCatalogcount.CountofItems = Convert.ToInt32(item1.itemcount);
double x = Convert.ToDouble(item1.itemcount);
double y = qs.Ipp;
double z = x/y;
int a = Convert.ToInt32(z);
//double value = 2635.215;
var values = z.ToString(CultureInfo.InvariantCulture).Split('.');
int firstValue = Convert.ToInt32(values[0]);
long secondValue = Convert.ToInt64(values[1]);
if(secondValue > 1)
{
result_lstCatalogcount.Pagination = firstValue + 1;
}
else
{
result_lstCatalogcount.Pagination = firstValue;
}
你做了什麼調試? – 2015-03-03 14:11:10
調試通過並看看裏面'values'的內容。我敢打賭這不是你所期望的...... – HimBromBeere 2015-03-03 14:16:43