-
Notifications
You must be signed in to change notification settings - Fork 639
/
Copy pathDinnerMenuEnum.cs
48 lines (42 loc) · 995 Bytes
/
DinnerMenuEnum.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections;
namespace IteratorPattern
{
public class DinnerMenuEnum : IEnumerator
{
private readonly Menu[] _items;
private int _position = -1;
public DinnerMenuEnum(Menu[] items)
{
_items = items;
}
public void Dispose()
{
throw new System.NotImplementedException();
}
public bool MoveNext()
{
_position++;
return (_position < _items.Length);
}
public void Reset()
{
_position = -1;
}
object IEnumerator.Current => Current;
public Menu Current
{
get
{
try
{
return _items[_position];
}
catch (IndexOutOfRangeException)
{
throw new InvalidOperationException();
}
}
}
}
}