Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

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

Select an option

Save soheil-moonesi/771c4068f19ae1bbb2d031acdec54292 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 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