Lecture overview -- Keyboard shortcut: 'u'  Previous page: Generic Types -- Keyboard shortcut: 'p'  Next page: Constraints: Strings of comparable elements -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 9 : 21
Object-oriented Programming in C#
Generic Types and Methods
Constraints on Formal Type Parameters

It is possible to express a number of constraints on a formal type parameter

The more constraints on T, the more we can do on T-objects in the body of C<T>

class C<S,T>: D  
    where T: A, ICloneable
    where S: B {
 ...
}

class E<T>: D
    where T: class{
 ...
}

class F<T>: D
    where T: struct{
 ...
}

class G<T>: D
    where T: new(){
 ...
}

Illustrations of the various constraints on type parameters.