Q:

Error: (using List class) Index was outside the bounds of array

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.
**Update:I sincerely apologize. I uploaded the wrong code. It is suppose to be this code:
Code:
struct studentInfo
{  
  public string studentID;
  public string major;
}  

public partial class Form1 : Form
{
    private List<studentInfo> studentList = new List<studentInfo>();

    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();
    }
}

A:

My guess would be that SelectedIndexChanged is ran at the start (before you select anything) and at that point nameListBox.SelectedIndex would be -1 and you can't get the "negative 1 position's item" in a list. I would make sure that the selected index is valid 
https://msdn.microsoft.com/fr-fr/library/system.windows.forms.listbox.selectedindex(v=vs.110).aspx
"A zero-based index of the currently selected item.A value of negative one (-1) is returned if no item is selected."
I would change the code as such:
private void nameListBox_SelectedIndexChanged(object sender, EventArgs e)
{
    int index = nameListBox.SelectedIndex;
    if(index !=-1)
    {
        phoneLabel.Text = phoneList[index].phone;
    }
    // else do nothing, the selected item didn't really change, it's just called for the first time, think of it as the control saying "hey i just got created and i'm notifying you that the selected item is now nothing"
}

A:

You have to guard SelectedIndex, when controls are initially created SelectedIndex is set to -1
private void nameListBox_SelectedIndexChanged(object sender, EventArgs e)
{
    if(nameListBox.SelectedIndex >=0)
    {
         int index = nameListBox.SelectedIndex;

         phoneLabel.Text = phoneList[index].phone;
    } 
}

