2010-04-13 Sebastien Pouliot <sebastien@ximian.com>
[mono-project.git] / mcs / tests / test-393.cs
blob9eba405cec4a8c185f93389894da634ac8483eca
1 // Compiler options: -langversion:default
2 // Test for covariance support in delegates
3 //
5 using System;
7 public class A {
8 protected string name;
10 public A (string name)
12 this.name = "A::" + name;
15 public A ()
19 public string Name {
20 get {
21 return name;
26 public class B : A {
27 public B (string name)
29 this.name = "B::" + name;
32 public B ()
37 public class C : B {
38 public C (string name)
40 this.name = "C::" + name;
44 public class Tester {
46 delegate A MethodHandler (string name);
48 static A MethodSampleA (string name)
50 return new A (name);
53 static B MethodSampleB (string name)
55 return new B (name);
58 static C MethodSampleC (string name)
60 return new C (name);
63 static void Main ()
65 MethodHandler a = MethodSampleA;
66 MethodHandler b = MethodSampleB;
67 MethodHandler c = MethodSampleC;
69 A instance1 = a ("Hello");
70 A instance2 = b ("World");
71 A instance3 = c ("!");
73 Console.WriteLine (instance1.Name);
74 Console.WriteLine (instance2.Name);
75 Console.WriteLine (instance3.Name);