我用List来存储值,如果数据是有限的,它的工作正常,如果数据在计数中超过15o,那么我得到以下错误 索引超出了数组的范围...... Plz提出了一个想法来解决这个问题。如何解决这个错误:索引超出了数组的边界
List<string> code = new List<string>();
private void btn_browse_Click(object sender, EventArgs e)
{
DialogResult fileopen = openFileDialog1.ShowDialog();
string filename = openFileDialog1.FileName;
txt_filename.Text = filename;
try
{
StreamReader readtxtfile = new StreamReader(filename);
String line = null;
string str = null;
char[] separate = { ',' };
string[] words;
while ((str = readtxtfile.ReadLine()) != null)
{
words = str.Split(separate);
code.Add(Convert.ToString(words[0]) + '-' + Convert.ToString(words[2]).Trim());
}
}
...做出更大的数组?动态扩展它?如果您不想提供更多详细信息,则无法提供帮助。 – nneonneo
你能粘贴一些代码吗? – secondflying
你能告诉我们一些你访问数据的代码吗? – CrazyCasta