What is Yield Statement?

 Posted by Rajnilari2015 on 9/28/2015 | Category: C# Interview questions | Views: 1657 | Points: 40

It performs ITERATION .
When we use the yield keyword in a statement, we indicate that the method, operator, or get accessor in which it appears is an iterator.
It creates a state machine "under the covers" that remembers where you were on each additional cycle of the function and picks up from there. In short,Yield has two great uses

a) It helps to provide custom iteration with out creating temp collections.

b) It helps to do stateful iteration.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response