How do I fix this error : index was outside the bounds of the array : <p>We have to make a GUI based program for campus.We basically have to create a 2 player battle based game where users have to enter their stats and those stats were used to for the battle.There was no other user input.I managed to complete it but when I ran the program I received this error:</p>

<p>Unhandled exception has occurred in your application .If you click 
Continue the application will ignore this error and attempt to continue .
If you click Quit the application will close immediately 
Index was outside the bounds of the array </p>

<p>My Code :</p>

<pre><code>    public Form1()
    {

        InitializeComponent();

    }
    //Declaring Jaggered Array
    string[][] playerstat = new string[2][];


    private void button1_Click(object sender, EventArgs e)
    {
        //Retrieving information from textboxes for player 1
        string name1 = txtName1.Text;
        string htpt1 = txtHtPt1.Text;
        string attack1 = txtAttack1.Text;
        string def1 = txtDef1.Text;
        //Assigning Player1 Values
        playerstat[0] = new string[4] { name1, htpt1, attack1, def1 };

    }

    private void panel4_Paint(object sender, PaintEventArgs e)
    {

    }

    private void button2_Click(object sender, EventArgs e)
    {
        //Retrieving information from textboxes for player 2
        string name2 = txtName2.Text;
        string htpt2 = txtHtPt2.Text;
        string attack2 = txtAttack2.Text;
        string def2 = txtDef2.Text;
        //Assigning Player2 Values
        playerstat[1] = new string[4] { name2, htpt2, attack2, def2 };
    }


    private void btnFight_Click(object sender, EventArgs e)
    {

        string p1name = playerstat[0][1];

        string sp1hp = playerstat[0][2];
        int p1hp = Int32.Parse(sp1hp);

        string sp1a = playerstat[0][3];
        int p1a = Int32.Parse(sp1a);

        string sp1d = playerstat[0][4];
        int p1d = Int32.Parse(sp1d);


        string p2name = playerstat[1][1];

        string sp2hp = playerstat[1][2];
        int p2hp = Int32.Parse(sp1hp);

        string sp2a = playerstat[1][3];
        int p2a = Int32.Parse(sp1a);

        string sp2d = playerstat[1][4];
        int p2d = Int32.Parse(sp1d);

        //Fighting Loop
        while(!(p1hp == 0) || !(p2hp == 0))
        {
            p2hp = p1a - (p2hp + p2d);
            txtFOP.Text = p1name + " deals " + p1a + " damage to " + p2name + " who now has " + p2hp;

            p1hp = p2a - (p1hp + p1d);
            txtFOP.Text = p2name + " deals " + p2a + " damage to " + p1name + " who now has " + p1hp;
        }
    }
}
</code></pre>

<p>}</p>
