title: Adding item to Dictionary returns System.IndexOutOfRangeException: Index was outside the bounds of the array
body: <p>I have the following code below:</p>
  
  <pre><code>List&lt;string&gt; group = new List&lt;string&gt;();
  List&lt;int&gt; groupInNumber = new List&lt;int&gt;();
  Dictionary&lt;string, List&lt;string&gt;&gt; dicMyMap = new Dictionary&lt;string, List&lt;string&gt;&gt;();
  Dictionary&lt;string, int[]&gt; a = new Dictionary&lt;string, int[]&gt;();
  Dictionary&lt;string, string[]&gt; b = new Dictionary&lt;string, string[]&gt;();
  
  private void SetData(out ExpandableListViewAdapter mAdapter)
      {
          int[] currentStatus = a["currentStatus"];
          string[] statusDesc = b["description"];
          int[] ticketID = a["ticketID"];
  
          foreach (int s in currentStatus)
          {
              if (s == 1)
              {
                  group.Add(statusDesc[0]);
              }
              else if (s == 2)
              {
                  group.Add(statusDesc[1]);
              }
              else if (s == 3)
              {
                  group.Add(statusDesc[2]);
              }
              else if (s == 4)
              {
                  group.Add(statusDesc[3]);
              }
              else if (s == 5)
              {
                  group.Add(statusDesc[4]);
              }
              else if (s == 6)
              {
                  group.Add(statusDesc[5]);
              }
              else if (s == 7)
              {
                  group.Add(statusDesc[6]);
              }
              else if (s == 8)
              {
                  group.Add(statusDesc[7]);
              }
              else if (s == 9)
              {
                  group.Add(statusDesc[8]);
              }
              else if (s == 10)
              {
                  group.Add(statusDesc[9]);
              }
          }
  
          for (int p = 0; p &lt;= ticketID.Count(); p++)
          {
              groupInNumber.Add(ticketID[p]);
          }
  
          List&lt;string&gt; ticket = new List&lt;string&gt;();
          for (int z = 0; z &lt;= ticketID.Count(); z++)
          {
              string tix = ticketID[z].ToString();
              ticket.Add(tix);
              dicMyMap.Add(groupInNumber[z].ToString(), ticket);
              ticket.Remove(tix);
          }
  
          mAdapter = new ExpandableListViewAdapter(this, group, dicMyMap);
      }
  </code></pre>
  
  <p>The error occurs here, <code>groupInNumber.Add(ticketID[p]);</code> What I don't understand is why the index is outside the bounds when <code>0</code> should be referring to the first value inside the array. I tried counting the items in <code>int[] ticketID = a["ticketID"];</code>, isn't null, returned <code>39</code> (number of items in the array).</p>