我用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