2 // Important test: Type parameters and boxing (26.7.3).
4 // This tests the constrained_ prefix opcode.
8 public interface ICounter
13 namespace ValueTypeCounters
15 public struct SimpleCounter
: ICounter
19 public void Increment ()
25 public struct PrintingCounter
: ICounter
29 public override string ToString ()
31 return Value
.ToString ();
34 public void Increment ()
40 public struct ExplicitCounter
: ICounter
44 public override string ToString ()
46 return Value
.ToString ();
49 void ICounter
.Increment ()
55 public struct InterfaceCounter
: ICounter
59 public override string ToString ()
61 return Value
.ToString ();
64 void ICounter
.Increment ()
69 public void Increment ()
76 namespace ReferenceTypeCounters
78 public class SimpleCounter
: ICounter
82 public void Increment ()
88 public class PrintingCounter
: ICounter
92 public override string ToString ()
94 return Value
.ToString ();
97 public void Increment ()
103 public class ExplicitCounter
: ICounter
107 public override string ToString ()
109 return Value
.ToString ();
112 void ICounter
.Increment ()
118 public class InterfaceCounter
: ICounter
122 public override string ToString ()
124 return Value
.ToString ();
127 void ICounter
.Increment ()
132 public void Increment ()
141 using V
= ValueTypeCounters
;
142 using R
= ReferenceTypeCounters
;
147 public static void Foo (T x
)
149 Console
.WriteLine (x
.ToString ());
151 Console
.WriteLine (x
.ToString ());
157 public static void Main ()
159 Test
<V
.SimpleCounter
>.Foo (new V
.SimpleCounter ());
160 Test
<V
.PrintingCounter
>.Foo (new V
.PrintingCounter ());
161 Test
<V
.ExplicitCounter
>.Foo (new V
.ExplicitCounter ());
162 Test
<V
.InterfaceCounter
>.Foo (new V
.InterfaceCounter ());
163 Test
<R
.SimpleCounter
>.Foo (new R
.SimpleCounter ());
164 Test
<R
.PrintingCounter
>.Foo (new R
.PrintingCounter ());
165 Test
<R
.ExplicitCounter
>.Foo (new R
.ExplicitCounter ());
166 Test
<R
.InterfaceCounter
>.Foo (new R
.InterfaceCounter ());