C# Async Streams

2021-07-02 19:03

阅读:614

标签:reac   com   技术   rsa   load   stream   class   new   yield   

先看代码

using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace AsyncStream
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var product = new Productor();

            var numbers = await product.GetNumbersAsync();
            foreach(var number in numbers)
            {
                Console.WriteLine(number);
            }

            return;

            await foreach(var number in product.EnumerateNumbersAsync())
            {
                Console.WriteLine(number);
            }
        }
    }

    public class Productor
    {
        public async Task> GetNumbersAsync()
        {
            List numbers = new();
            for (int tens = 0; tens  EnumerateNumbersAsync()
        {
            for (int tens = 0; tens 

上部分执行结果如下图
技术图片

注释 main 函数 return ;之前的代码

        static async Task Main(string[] args)
        {
            var product = new Productor();

            // var numbers = await product.GetNumbersAsync();
            // foreach(var number in numbers)
            // {
            //     Console.WriteLine(number);
            // }

            // return;

            await foreach(var number in product.EnumerateNumbersAsync())
            {
                Console.WriteLine(number);
            }
        }

执行结果如下图

技术图片

C# Async Streams

标签:reac   com   技术   rsa   load   stream   class   new   yield   

原文地址:https://www.cnblogs.com/microestc/p/14961522.html


评论


亲,登录后才可以留言!