2010-04-13 Sebastien Pouliot <sebastien@ximian.com>
[mono-project.git] / mcs / tests / gtest-021.cs
blobc57b3df11245a1e55a96445a38c96b0ef8cf5a84
1 // Testing the default value expressions (14.5.13)
3 using System;
5 class Foo<T>
7 T[] t;
9 public Foo (int n)
11 t = new T [n];
12 for (int i = 0; i < n; i++)
13 t [i] = default (T);
16 public void Test ()
18 X.Print (t [0]);
22 class Bar<T>
24 public void Test ()
26 X.Print (default (X));
27 X.Print (default (T));
28 X.Print (default (S));
32 struct S
34 public readonly string Hello;
36 S (string hello)
38 this.Hello = hello;
41 public override string ToString ()
43 return String.Format ("S({0})", Hello);
48 class X
50 public static void Print (object obj)
52 if (obj == null)
53 Console.WriteLine ("NULL");
54 else
55 Console.WriteLine ("OBJECT: {0} {1}", obj, obj.GetType ());
58 static void Main ()
60 Foo<string> a = new Foo<string> (4);
61 a.Test ();
63 Bar<int> b = new Bar<int> ();
64 b.Test ();
65 Bar<X> c = new Bar<X> ();
66 c.Test ();