title: Error: (using List class) Index was outside the bounds of array
body: <p>I'm working on a project and I'm a beginner in programming in c#, and somehow there is a problem that I cannot solve. How it happened: In executing the code, the application launches successfully but an exception
  shows that the "Index was outside the bounds of array". Afterwards, I was able to click items on a listbox and it shows the second object on the textbox. So... It seems like it works(clicking on listbox's item) but I cannot figure out why it would throw an exception about the array. Beneath is the current code that I have.</p>
  
  <p>**Update:I sincerely apologize. I uploaded the wrong code. It is suppose to be this code:</p>
  
  <p>Code:</p>
  
  <pre><code>struct studentInfo
  {  
    public string studentID;
    public string major;
  }  
  
  public partial class Form1 : Form
  {
      private List&lt;studentInfo&gt; studentList = new List&lt;studentInfo&gt;();
  
      public Form1()
      {
          InitializeComponent();
      }
  
  
      private void ReadInputFile()
      {
          try
          {
              StreamReader inputFile;
              string line = "";
  
              studentInfo student = new studentInfo();
  
              char[] delimiter = { ',' };
  
              inputFile = File.OpenText("Student Info.txt");
  
              while (!inputFile.EndOfStream)
              {
                  line = inputFile.ReadLine();
  
                  string[] token = line.Split(delimiter);
  
                  student.studentID = token[0];
                  student.major = token[1];
  
                  studentList.Add(student);
  
              }
  
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message);
          }
      }
      private void DisplaystudentID()
      {
          foreach (studentInfo student in studentList)
          {
              studentInfoListBox.Items.Add(student.studentID);
          }
      }
  
      private void DisplayNames()
      {
  
      }
      private void button1_Click(object sender, EventArgs e)
      {
          ReadInputFile();
  
          DisplaystudentID();
      }
  
      private void studentInfoListBox_SelectedIndexChanged(object sender, EventArgs e)
      {
          int index = studentInfoListBox.SelectedIndex;
  
          majorTextBox.Text = studentList[index].major;
  
  
      }
  
      private void button3_Click(object sender, EventArgs e)
      {
          Application.Exit();
      }
  }
  </code></pre>