forked from WeihanLi/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
38 lines (34 loc) · 1.06 KB
/
Program.cs
File metadata and controls
38 lines (34 loc) · 1.06 KB
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
using System;
namespace IteratorPattern
{
public class Program
{
public static void Main(string[] args)
{
var aggregate = new ConcreteAggregate
{
[0] = "大鸟",
[1] = "小菜",
[2] = "行李",
[3] = "老外",
[4] = "公交员工",
[5] = "小偷"
};
Console.WriteLine("ConcreteIterator:");
Iterator iterator = new ConcreteIterator(aggregate);
do
{
Console.WriteLine($"{iterator.CurrentItem()} 请买车票");
iterator.Next();
} while (!iterator.IsDone());
Console.WriteLine("ConcreteIteratorDesc:");
Iterator iteratorDesc = new ConcreteIteratorDesc(aggregate);
do
{
Console.WriteLine($"{iteratorDesc.CurrentItem()} 请买车票");
iteratorDesc.Next();
} while (!iteratorDesc.IsDone());
Console.ReadLine();
}
}
}