-
Notifications
You must be signed in to change notification settings - Fork 648
/
Copy pathDinnerMenu.cs
44 lines (36 loc) · 924 Bytes
/
DinnerMenu.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
using System;
using System.Collections;
namespace IteratorPattern
{
public class DinnerMenu
{
private const int Max = 1;
private int _count;
private Menu[] _items;
public IEnumerable Items
{
get
{
return new DinnerMenuIterator(_items);
}
}
public DinnerMenu()
{
_items = new Menu[Max];
AddItems("Hamburger", "Hamburger with cheese and onions", 160, false);
}
private void AddItems(string name, string description, int price, bool veg)
{
var item = new Menu(name, description, price, veg);
if (_count <= Max)
{
_items[_count] = item;
_count++;
}
else
{
throw new IndexOutOfRangeException();
}
}
}
}