File tree Expand file tree Collapse file tree
DesignPatterns/IteratorPattern/IteratorPattern Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ class ConcreteAggregate : Aggregate
2020
2121 public override Iterator CreateIterator ( )
2222 {
23-
23+ return new ConcreteIterator ( this ) ;
2424 }
2525
2626 public int Size ( )
@@ -35,7 +35,7 @@ public Object GetItem(int i)
3535
3636 public void SetItems ( int i , Object obj )
3737 {
38- items [ i ] = obj ;
38+ items . Add ( obj ) ;
3939 }
4040 }
4141}
Original file line number Diff line number Diff line change 4242 <Reference Include =" System.Xml" />
4343 </ItemGroup >
4444 <ItemGroup >
45+ <Compile Include =" Aggregate.cs" />
46+ <Compile Include =" Iterator.cs" />
4547 <Compile Include =" Program.cs" />
4648 <Compile Include =" Properties\AssemblyInfo.cs" />
4749 </ItemGroup >
Original file line number Diff line number Diff line change @@ -10,6 +10,18 @@ class Program
1010 {
1111 static void Main ( string [ ] args )
1212 {
13+ ConcreteAggregate aggregate = new ConcreteAggregate ( ) ;
14+
15+ for ( int i = 0 ; i < 10 ; i ++ )
16+ {
17+ aggregate . SetItems ( i , "求职者" + ( i + 1 ) ) ;
18+ }
19+ Iterator iterator = aggregate . CreateIterator ( ) ;
20+ while ( ! iterator . IsDone ( ) )
21+ {
22+ Console . WriteLine ( iterator . CurrentItem ( ) + "来我公司面试" ) ;
23+ iterator . Next ( ) ;
24+ }
1325 }
1426 }
1527}
You can’t perform that action at this time.
0 commit comments