我总是让数组索引越界?
我尝试将 mymatches.Count 更改为 +1 和 -1 但它仍然超出范围。
为什么?
public string[] readAllScripts()
{
string[] scripts = txt_script.Lines;
int arraysize = scripts.Length;
int x = 0;
int y = 0;
MessageBox.Show(arraysize.ToString());
//string pattern = "[a-zA-Z]*";
string[][] scriptarray = new string[arraysize][];
for (int i = 0; i < scripts.Length; i++)
{
MatchCollection mymatches = Regex.Matches(scripts[i], "[a-zA-Z]*");
scriptarray[i] = new string[mymatches.Count];
foreach (Match thematch in mymatches)
{
scriptarray[x][y] = thematch.Value;
y++;
}
x++;
}
return scripts;
}