i used List to store the value, its working correctly if the data is limited, if the data is exceed more 15o in counts, then i am getting the following error
Index was outside the bounds of the array…Plz suggest an idea to overcome this problem.
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());
}
}
This error is not because of your list but it came from your array “words”. First check length of array like this
Make sure that whenever length of array is less then 2 it will not add in your list.
Hope this helps…