我已经写了一段代码,我在下面分两位小数。当代码中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