title: Replace for-switch loop with a Linq query
body: <p>I have a Message object which wraps a message format I do not have control over. The format is a simple list of Key/Value pairs. I want to extract a list of Users from a given Message. For example given the following message...</p>
  
  <pre><code>1. 200-&gt;....
  2. 300-&gt;....
  3. ....
  4. 405-&gt;.... 
  5. 001-&gt;first_user_name
  6. 002-&gt;first_user_phone
  7. 003-&gt;first_user_fax
  8. 001-&gt;second_user_name
  9. 001-&gt;third_user_name
  10. 002-&gt;third_user_phone
  11. 003-&gt;third_user_fax
  12. 004-&gt;third_user_address
  13. .....
  14. 001-&gt;last_user_name
  15. 003-&gt;last_user_fax  
  </code></pre>
  
  <p>I want to extract four Users with the provided properties set. The initial keys 200/300....405 represent fields I don't need and can skip to get to the User data. </p>
  
  <p>Each users data is in consecutive fields but the number of fields varies depending on how much information is known about a user. The following method does what I'm looking for. It uses an enumeration of possible key types and a method to find the index of the first field with user data. </p>
  
  <pre><code>private List&lt;User&gt; ParseUsers( Message message )
  {
      List&lt;User&gt; users = new List&lt;User&gt;( );
      User user = null; String val = String.Empty;
  
      for( Int32 i = message.IndexOfFirst( Keys.Name ); i &lt; message.Count; i++ ) 
      {
          val = message[ i ].Val;
  
          switch( message[ i ].Key )
          {
              case Keys.Name:
                  user = new User( val );
                  users.Add( user ); 
                  break;
              case Keys.Phone:
                  user.Phone = val;
                  break;
              case Keys.Fax:
                  user.Fax = val;
                  break;
              case Keys.Address:
                  user.Address = val;
                  break;
              default:
                  break;
          }
      }
  
      return users;
  }
  </code></pre>
  
  <p>I'm wondering if its possible to replace the method with a Linq query. I'm having trouble telling Linq to select a new user and populate its fields with all matching data until you find the start of the next user entry. </p>
  
  <p>Note: Relative key numbers are random (not 1,2,3,4) in the real message format.</p>