Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / tests / gtest-iter-11.cs
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4
5 class Foo {}
6         
7 class Bar : Foo {
8         public string Name { get; set; }
9 }
10
11 class Collection<T> : IEnumerable<T> where T : Foo {
12         List<T> list = new List<T> ();
13
14         public void Add (T t)
15         {
16                 list.Add (t);
17         }
18
19         public IEnumerator<T> GetEnumerator ()
20         {
21                 foreach (T t in list)
22                         yield return t;
23         }
24
25         IEnumerator IEnumerable.GetEnumerator ()
26         {
27                 return GetEnumerator ();
28         }
29 }
30
31 class BarCollection : Collection<Bar> {}
32
33 class Program {
34
35         public static int Main ()
36         {
37                 var collection = new BarCollection () {
38                         new Bar { Name = "a" },
39                         new Bar { Name = "b" },
40                         new Bar { Name = "c" },
41                 };
42
43                 foreach (var bar in collection)
44                         Console.WriteLine (bar.Name);
45                 
46                 return 0;
47         }
48 }