Created
March 5, 2024 08:17
-
-
Save soheil-moonesi/2f4f301a41d5c145b5d37e0d5623fdfc 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 OpenRestaurantsEnumerator : IEnumerator | |
| { | |
| private readonly List<Restaurant> _restaurants; | |
| private int _position = -1; | |
| public OpenRestaurantsEnumerator(List<Restaurant> restaurants) | |
| { | |
| _restaurants = restaurants; | |
| } | |
| public object Current | |
| { | |
| get | |
| { | |
| if (_position == -1 || _position >= _restaurants.Count) | |
| throw new InvalidOperationException(); | |
| return _restaurants[_position]; | |
| } | |
| } | |
| public bool MoveNext() | |
| { | |
| while(_position < _restaurants.Count) | |
| { | |
| _position++; | |
| if (_position < _restaurants.Count && _restaurants[_position].IsOpened) | |
| { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| public void Reset() | |
| { | |
| _position = -1; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment