Last active
April 19, 2020 05:57
-
-
Save masaab/28664715fe3a1ccc25a6398226a30085 to your computer and use it in GitHub Desktop.
Creating bread in restaurant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Threading.Tasks; | |
| namespace ConsoleApp3 | |
| { | |
| class Program | |
| { | |
| private const int _numberofBreads = 10; | |
| static async Task Main(string[] args) | |
| { | |
| Console.WriteLine("Start Calculating Breads in India and Yemen!"); | |
| Restaurant restaurant = new Restaurant(); | |
| IEnumerable<int> breadFromIndia = await restaurant.GetBreadIndianWayAsync(_numberofBreads); | |
| IAsyncEnumerable<int> breadsFromYemen = restaurant.GetBreadYemeniWayAsync(_numberofBreads); | |
| foreach (var item in breadFromIndia) | |
| { | |
| Console.WriteLine($"{item}: Indian Bread Ready To serve"); | |
| } | |
| await foreach (var item in breadsFromYemen) | |
| { | |
| Console.WriteLine($"{item}: Indian Bread Ready To serve"); | |
| } | |
| } | |
| } | |
| public class Restaurant | |
| { | |
| public async Task<IEnumerable<int>> GetBreadIndianWayAsync(int numberOfBreads) | |
| { | |
| List<int> breadList = new List<int>(); | |
| for (int i = 1; i <= numberOfBreads; i++) | |
| { | |
| Console.WriteLine($"Baking Indian Bread: {i}"); | |
| await Task.Delay(1000); | |
| breadList.Add(i); | |
| } | |
| return breadList; | |
| } | |
| public async IAsyncEnumerable<int> GetBreadYemeniWayAsync(int numberOfBreads) | |
| { | |
| for (int i = 1; i <= numberOfBreads; i++) | |
| { | |
| Console.WriteLine($"Baking Yemeni Bread:{i}"); | |
| await Task.Delay(1000); | |
| yield return i; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment