-
Notifications
You must be signed in to change notification settings - Fork 639
/
Copy pathBreakfastMenuEnum.cs
49 lines (42 loc) · 1013 Bytes
/
BreakfastMenuEnum.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
49
using System;
using System.Collections;
namespace IteratorPattern
{
public class BreakfastMenuEnum : IEnumerator
{
private readonly ArrayList _items;
private int _position = -1;
public BreakfastMenuEnum(ArrayList items)
{
_items = items;
}
public void Dispose()
{
throw new System.NotImplementedException();
}
public bool MoveNext()
{
_position++;
return (_position < _items.Count);
}
public void Reset()
{
_position = -1;
}
object IEnumerator.Current => Current;
public Menu Current
{
get
{
try
{
return (Menu)_items[_position];
}
catch (IndexOutOfRangeException)
{
throw new InvalidOperationException();
}
}
}
}
}