C# 索引超出了数组界限。

来源:百度知道 编辑:UC知道 时间:2024/06/21 14:38:11
string str = Convert.ToString(rowview["wjbj"]);
string[] stes=new string []{};//
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"<img.*?src=""(?<src>[^""]*)""[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.MatchCollection m = reg.Matches(str); //设定要查找的字符串
for (int i = 0; i < m.Count; i++)
{
stes[i]= m[i].Groups["src"].ToString();//索引超出了数组界限。

}

this.DropDownList1.DataSource = stes;
this.DropDownList1.DataBind();

不知道那里出问题了

stes = new string[m.Count];//在此声明stes
for (int i = 0; i < m.Count; i++)

i < m.Count-1
试试
这个问题一般是:"比如你的数组长度只有5个!而你去读取数组第六个元素!才会报错的!"

string[] stes=new string []{};//
这错了
string[] stes=new string [m.Count]{};

你把完整的代码贴出来