generics/constraints/class-struct-constraints.cs - Two generic classes C and D - with the necessary constraints. | Lecture 11 - slide 11 : 21 Program 3 |
/* Example from Hansen and Sestoft: C# Precisely */ class C<T> where T: class{ T f = null; } class D<U> where U: struct{ U? f; } class Appl{ // Does NOT compile: C<double> c = new C<double>(); D<A> d = new D<A>(); // OK: C<A> c1 = new C<A>(); D<double> d1 = new D<double>(); } class A{}