Why do we need iterators in c#?

前端 未结 10 1898
情话喂你
情话喂你 2021-02-05 18:35

Can somebody provide a real life example regarding use of iterators. I tried searching google but was not satisfied with the answers.

10条回答
  •  滥情空心
    2021-02-05 19:12

    IEnumerator myIterator = listOfStackOverFlowQuestions.GetEnumerator();
    while (myIterator.MoveNext())
    {
      Question q;
      q = myIterator.Current;
      if (q.Pertinent == true)
         PublishQuestion(q);
      else
         SendMessage(q.Author.EmailAddress, "Your question has been rejected");
    }
    
    
    foreach (Question q in listOfStackOverFlowQuestions)
    {
        if (q.Pertinent == true)
            PublishQuestion(q);
        else    
            SendMessage(q.Author.EmailAddress, "Your question has been rejected");
    }
    

提交回复
热议问题