我想从网址****.aspx?cat=1+2+3+4+5中获得这些数字组成的list.
由QueryString获得cat的值后,再由
var catList = new List<int>();
string cat = null;
if (!string.IsNullOrEmpty(Request.QueryString.Get("cat")))
{
cat = Request.QueryString.Get("cat");
string[] str = cat.Split('+');
for (int i = 0; i < str.Length; i++)
{
if (str[i] != null)
{
int a = Convert.ToInt32(str[i]);
catList.Add(a);
}
}
}
却在int a = Convert.ToInt32(cats[i]);时提示“System.FormatException: 输入字符串的格式不正确。”
我检查了不是空值,用其他方法读出了的确是数字值。foreach方法也试过了。
请问是什么地方出问题了呢?
cats[i])的值是不是为空,或者里面有空格等符号。