The code is as follows: After using yield return in the Documents1 method, the next time you enter the Documents1 method is to execute from the last yield return part
usingSystem;usingSystem.Collections;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading;usingSystem.Threading.Tasks;namespacec data structure and algorithm {classProgram {Static voidMain (string[] args) {List<string> DOCS1 =Newlist<string>(); Docs1. ADD ("1"); Docs1. ADD ("2"); Docs1. ADD ("3"); Docs1. ADD ("4"); Docs1. ADD ("5"); foreach(stringIteminchDocuments1 (DOCS1)) {Console.WriteLine ("Get Value:"+item); Thread.Sleep ( -); } console.readkey (); } StaticIEnumerable Documents1 (list<string>docs) { foreach(varIteminchdocs) { if(Item! ="4") {Console.WriteLine ("return Value:"+item); //The yield return statement returns an element of the collection and moves to the next element yield returnitem; Console.WriteLine ("Run out of values:"+item); }} console.write ("{0}","Cycle Complete"); } }}
C # yield return process understanding