Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save soheil-moonesi/8237c12cd9504c3215b7f022a66ffe6c to your computer and use it in GitHub Desktop.

Select an option

Save soheil-moonesi/8237c12cd9504c3215b7f022a66ffe6c to your computer and use it in GitHub Desktop.
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