title: IEnumerable - Move Next
body: <p>I have an IEnumerable from which I need to fetch each item and display it one by one. The displaying is not a continuous process..i.e I should fetch one item and display it on the UI, then wait for some user feedback on that item, and then move on to the next item. For example from the below code, I need to fetch a question, then display it to the user, then user hits enter, and then I move on to fetching the next question. </p>
  
  <p>My Question is how do I do that? Is IEnumerable the best way of achieving this or should I revert to list and start storing the indexes and increment it one by one?</p>
  
  <p>Please note that I'm using .NET 3.5.</p>
  
  <p>Code:</p>
  
  <pre><code>class Program
      {
          static void Main(string[] args)
          {
              Exam exam1 = new Exam()
                               {
                                   Questions = new List&lt;Question&gt;
                                                   {
                                                       new Question("question1"),
                                                       new Question("question2"),
                                                       new Question("question3")
                                                   }
                               };
              var wizardStepService = new WizardStepService(exam1);
              var question = wizardStepService.GetNextQuestion();
              //Should output question1
              Console.WriteLine(question.Content);
              Console.ReadLine();
              //Should output question2 but outputs question1
              question = wizardStepService.GetNextQuestion();
              Console.WriteLine(question.Content);
              Console.ReadLine();
              //Should output question3 but outputs question1
              question = wizardStepService.GetNextQuestion();
              Console.WriteLine(question.Content);
              Console.ReadLine();
          }
      }
  
      public class Question
      {
          private readonly string _text;
          public Question(string text)
          {
              _text = text;
          }
  
          public string Content { get { return _text; } }
      }
  
      internal class Exam
      {
          public IEnumerable&lt;Question&gt; Questions { get; set; }
      }
  
      internal class WizardStepService
      {
          private readonly Exam _exam;
          public WizardStepService(Exam exam)
          {
              _exam = exam;
          }
  
          public Question GetNextQuestion()
          {
            foreach (var question in _exam.Questions)
              {              
                //This always returns the first item.How do I navigate to next 
                //item when GetNextQuestion is called the second time?
                return question;
              }
  
              //should have a return type hence this or else not required.
              return null;
          }
      }
  </code></pre>