Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / tests / gtest-021.cs
1 // Testing the default value expressions (14.5.13)
2
3 using System;
4
5 class Foo<T>
6 {
7         T[] t;
8
9         public Foo (int n)
10         {
11                 t = new T [n];
12                 for (int i = 0; i < n; i++)
13                         t [i] = default (T);
14         }
15
16         public void Test ()
17         {
18                 X.Print (t [0]);
19         }
20 }
21
22 class Bar<T>
23 {
24         public void Test ()
25         {
26                 X.Print (default (X));
27                 X.Print (default (T));
28                 X.Print (default (S));
29         }
30 }
31
32 struct S
33 {
34         public readonly string Hello;
35
36         S (string hello)
37         {
38                 this.Hello = hello;
39         }
40
41         public override string ToString ()
42         {
43                 return String.Format ("S({0})", Hello);
44         }
45
46 }
47
48 class X
49 {
50         public static void Print (object obj)
51         {
52                 if (obj == null)
53                         Console.WriteLine ("NULL");
54                 else
55                         Console.WriteLine ("OBJECT: {0} {1}", obj, obj.GetType ());
56         }
57
58         public static void Main ()
59         {
60                 Foo<string> a = new Foo<string> (4);
61                 a.Test ();
62
63                 Bar<int> b = new Bar<int> ();
64                 b.Test ();
65                 Bar<X> c = new Bar<X> ();
66                 c.Test ();
67         }
68 }