title: Use foreach to loop through list (or array) as sequence of pairs
body: <p>I'm creating a simple program that reads username and password from Customers.txt file and verifies if it's correct. Customer.txt is formatted to have sequence of the username then password separated by commas (ignore safety concerns for the exercise):</p>
  
  <blockquote>
    <p>JohnDoe,1234,JaneDoe,5678,...</p>
  </blockquote>
  
  <p>Is it possible to create a <code>foreach</code> loop to iterate through the <code>strArray[]</code> and check pairs {<code>strArray[0]</code>, <code>strArray[1]</code>} then {<code>strArray[2]</code>,<code>strArray[3]</code>} and so on to see if user put the right credentials? </p>
  
  <pre><code>private void enter_click_Click(object sender, RoutedEventArgs e)
  {
      StreamReader reader1 = new StreamReader("Customers.txt");
      string text = reader1.ReadToEnd();
      reader1.Close();
  
      string[] Strarray = text.Split(',');
      StreamReader reader2 = new StreamReader("Admin.txt");
      string text2 = reader2.ReadToEnd();
      reader2.Close();
  
      string[] AdminArray = text2.Split(',');
      if (username_txt.Text == AdminArray[0] &amp;&amp; passwordBox1.Password == AdminArray[1])
      {
          AdminPage admin = new AdminPage();
          admin.Activate();
          admin.Show();
          method.CheckDate();
          return;
      }
      if (username_txt.Text == Strarray[0] &amp;&amp; passwordBox1.Password == Strarray[1])
          {
              ATM_Screen atm = new ATM_Screen();
              atm.Activate();
              atm.Show();
              method.CheckDate();
              return;
          }
  </code></pre>