Created
March 5, 2024 06:41
-
-
Save soheil-moonesi/771c4068f19ae1bbb2d031acdec54292 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 IEnumerator GetEnumerator() => restaurants.GetEnumerator(); | |
| } | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| Restaurants restaurants = new Restaurants(); | |
| foreach (Restaurant restaurant in restaurants) | |
| { | |
| Console.WriteLine(restaurant.Name); | |
| } | |
| //Output: | |
| //Pizza | |
| //Hamburger | |
| //Bread | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment