Page 4 : 21
Object-oriented Programming in C#
Generic Types and Methods
* Motivation for Generic Types
Operations on sets
The classes IntSet and StringSet
The class ObjectSet
Problems
* Generic Types
The generic class Set<T>
Generic Types
Constraints on Formal Type Parameters
Constraints: Strings of comparable elements
Another example of constraints
Variance
Generic structs
Generic interfaces: IComparable<T>
Generic equality interfaces
Generic Classes and Inheritance
* Generic Methods
Generic Methods
Generic Delegates
Predefined generic delegates
Generic types and methods - Pros and Cons
The class ObjectSet
A set of
Object
s fulfills all needs, but ...
The class ObjectSet.
A client of ObjectSet - working with sets of Die objects.
Output from the ObjectSet client program.
A client of ObjectSet - working with set of different types.
Output from the the client of ObjectSet - the version that works with sets of different types.
Class
ObjectSet
is not type safe
Use of class
Object
as element type requires a lot of casting