Created
March 5, 2024 08:52
-
-
Save soheil-moonesi/8237c12cd9504c3215b7f022a66ffe6c to your computer and use it in GitHub Desktop.
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
| class Restaurants : IEnumerable | |
| { | |
| readonly public List<Restaurant> restaurants = new List<Restaurant> | |
| { | |
| new Restaurant("Pizza", true), | |
| new Restaurant("Hamburger", false), | |
| new Restaurant("Bread", true) | |
| }; | |
| public GetEnumerator() => new OpenRestaurantsEnumerator(restaurants); | |
| } | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| Restaurants restaurants = new Restaurants(); | |
| foreach (Restaurant restaurant in restaurants) | |
| { | |
| Console.WriteLine(restaurant.Name); | |
| } | |
| //Output: | |
| //Pizza | |
| //Bread | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment