1 using System;
2 using System.Collections;
3 using System.IO;
4
5 public void PrintIntList(const List<int>& intList)
6 {
7 Console.WriteLine("intList:");
8 for (int i : intList)
9 {
10 Console.WriteLine(i);
11 }
12 }
13
14 public void AddOneToAll(List<int>& intList)
15 {
16 for (int& x : intList)
17 {
18 x = x + 1;
19 }
20 }
21
22 public void PrintStringList(const List<string>& stringList)
23 {
24 Console.WriteLine("stringList:");
25 for (const string& s : stringList)
26 {
27 Console.WriteLine(s);
28 }
29 }
30
31 public class Foo
32 {
33 public Foo(int x_) : x(x_)
34 {
35 }
36 public int X() const
37 {
38 return x;
39 }
40 private int x;
41 }
42
43 public TextWriter& operator<<(TextWriter& writer, const Foo& foo)
44 {
45 return writer << "Foo: " << foo.X();
46 }
47
48 public class MyCollection
49 {
50 public typedef List<Foo>.ConstIterator ConstIterator;
51 public typedef List<Foo>.Iterator Iterator;
52 public ConstIterator CBegin() const
53 {
54 return fooList.CBegin();
55 }
56 public ConstIterator Begin() const
57 {
58 return fooList.CBegin();
59 }
60 public Iterator Begin()
61 {
62 return fooList.Begin();
63 }
64 public ConstIterator CEnd() const
65 {
66 return fooList.CEnd();
67 }
68 public ConstIterator End() const
69 {
70 return fooList.CEnd();
71 }
72 public Iterator End()
73 {
74 return fooList.End();
75 }
76 public void Add(const Foo& foo)
77 {
78 fooList.Add(foo);
79 }
80 private List<Foo> fooList;
81 }
82
83 public void PrintMyCollection(const MyCollection& myCollection)
84 {
85 Console.WriteLine("myCollection:");
86 for (const Foo& foo : myCollection)
87 {
88 Console.Out() << foo << endl();
89 }
90 }
91
92 void main()
93 {
94 List<int> intList;
95 intList.Add(1);
96 intList.Add(2);
97 intList.Add(3);
98 PrintIntList(intList);
99 AddOneToAll(intList);
100 PrintIntList(intList);
101 List<string> stringList;
102 stringList.Add("foo");
103 stringList.Add("bar");
104 PrintStringList(stringList);
105 MyCollection myCollection;
106 myCollection.Add(Foo(1));
107 myCollection.Add(Foo(2));
108 myCollection.Add(Foo(3));
109 PrintMyCollection(myCollection);
110 }