Page 7 : 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 generic class Set<T>
It is attractive to parameterize the class
Set
with its element type
T
The class
Set<T>
.
A client of
Set<T>
- working with sets of different types.
Output from the
Set<T>
client program.
Intersection, union, and difference: Operations on sets
An element access operation on sets
A generic Pair class
An actual type is provided when the class
Set
is used, for instance in a client class.