Regarding IndexOutOfRange error asp.net c#
<p>Hi
i am creating online quiz. For that i am creating arrays of answers selected by user. i used following code for that, it gives correct array but sometimes gives error "Index was outside the range"</p>

<pre><code>    //rsel is session values for selected answer
            int rsel = Convert.ToInt32(Session["rblsel"]);
// [Convert.ToInt32(Session["Counter"] indicates size of array of no. of questions
            int[] ansarray = new int[Convert.ToInt32(Session["Counter"]) - 1];

            int[] temp = (int[])Session["arrofans"];
            int j,n;

                if (temp == null)
                    n = 0;
                else
                    n = temp.Length;
                for (j = 0; j &lt; n; j++)
                {
                ansarray[j] = temp[j];
                }
                ansarray[j] = rsel;
                Session["arrofans"] = ansarray;
</code></pre>

<p>Help me to find out exact error. Asp.net,c#
Thank you.</p>
