title: Foreach going out of bounds while searching through array c#
body: <p>The purpose of my program is to take a data txt file and edit it, and/or make additions and subtractions to it.
  The text file format is like this:</p>
  
  <pre><code>Name|Address|Phone|# of people coming|isRSVP
  </code></pre>
  
  <p>The code I have seems to be doing it's job all the way up until I try to click one of the names within a <em>listbox</em> and it needs to search through the multidimensional array to pull information out and place within a set of <em>textboxes</em> where they can be edited. The problem is that the <em>foreach</em> loop I use gives me an <em>out of bounds</em> exception.  I tried to do a step into debug  to make sure the data is correct in the array and see the process.  Everything seems to do correctly but for some reason in the conditional statement <code>person[0]==listbox1.selectedIndex</code>   isn't returning true even though both are the same as I seen through the step into process. Any help would be greatly appreciated. 
  This is my code:</p>
  
  <pre><code>StringBuilder newFile = new StringBuilder();
  static  string txtList= "guest_list.txt";    
  static string[] file = File.ReadAllLines(txtList);    
  static int x = file.Count();
  string[,] list = new string[x ,5];
  
  public void loadGuestList()
  {
  
      int count2 = 0;
      foreach (string line in file)
      {
          string[] sliced = line.Split('|');
          int count = 0;
  
          list[count2, count] = sliced[0];
          count++;
          list[count2, count] = sliced[1];
          count++;
          list[count2,count] = sliced[2];
          count++;
          list[count2,count]= sliced[3];
          count++;
          list[count2, count] = sliced[4];
          count++;
          listBox1.Items.Add(list[count2,0]);
          count2++;
      }
  }
  
  private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  {
      foreach (string person in list)
      {
          if (  person[0].ToString()==listBox1.SelectedItem.ToString())
          {
              addTxt.Text = char.ToString(person[1]);
              textPhone.Text = char.ToString(person[2]);
              textPeople.Text = char.ToString(person[3]);
              if (person[4] == 'n' )
              {
              }
              else
              {
                  chkRSVP.Checked = true;
              }
              break;
          }
      }
  }
  </code></pre>