IndexOutOfRange Exception from String.Format
<p>I want to search a file by the month of birth and display the results in label7. So what I want is to enter the number 11 into textbox5 press button4 and display all the enteries with a birthmonth of 11 into label7.text. The filename.txt is created in the first part of the program I now what to be able to search that filename.txt. Another example of what i am trying to do is. When the file was created data was entered Firstname, lastname, birthday, and birth month. I want to search that file by birth month and display the results in label7.</p>

<pre><code>public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void tabPage2_Click(object sender, EventArgs e)
    {

    }

    private void label3_Click(object sender, EventArgs e)
    {

    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {

    }

    private void textBox2_TextChanged(object sender, EventArgs e)
    {

    }

    private void maskedTextBox1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
    {

    }

    private void textBox3_TextChanged(object sender, EventArgs e)
    {

    }

    private void textBox4_TextChanged(object sender, EventArgs e)
    {

    }

    private void close_Click(object sender, EventArgs e)
    {
        Close();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        writetext();
        reset();

    }
    public void writetext()
    {

        using (TextWriter writer = File.AppendText("filename.txt"))

        {
         writer.WriteLine("First name, {0} Lastname, {1} Phone,{2} Day of birth,{3} Month of Birth{4}", textBox1.Text, textBox2.Text, maskedTextBox1.Text, textBox4.Text, textBox3.Text);
         MessageBox.Show(String.Format("First Name,{0} Lastname, {1} Phone,{2} Day of birth,{3} Month of Birth{4}", textBox1.Text, textBox2.Text, maskedTextBox1.Text, textBox4.Text, textBox3.Text)); 
        }
        }
    public void reset()
    {
        textBox1.Text = "";
        textBox2.Text = "";
        textBox3.Text = "";
        textBox4.Text = "";
        maskedTextBox1.Text = "";
    }

    private void button3_Click(object sender, EventArgs e)
    {
        Close(); 
     }

    private void button2_Click(object sender, EventArgs e)


    {
        readfile(); 


    }

    private void label7_Click(object sender, EventArgs e)
    {

    }

    private void button4_Click(object sender, EventArgs e)
    {
        string[] lines = ... 
    try
    { 
            int month = Int32.parse(textBox5.Text); 
            label7.Text = String.Format("Month of Birth {0}", lines[month]); 
        } 
    catch(Exception e){ 
        label7.Text = "Invalid input"; 
</code></pre>

<p>} </p>

<pre><code>    }
    public void readfile()
    {
        string[] lines = File.ReadAllLines("filename.txt");
        label6.Text = String.Join(Environment.NewLine, lines);

    }

    private void textBox5_TextChanged(object sender, EventArgs e)
    {

    }
}
</code></pre>

<p>}</p>
