C # yield return process understanding

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.