Lecture overview -- Keyboard shortcut: 'u'  Previous page: The generic class Set<T> -- Keyboard shortcut: 'p'  Next page: Constraints on Formal Type Parameters -- 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 8 : 21
Object-oriented Programming in C#
Generic Types and Methods
Generic Types

C# supports generic classes, generic structs, generic interfaces, and generic delegate types

  • Template

    • C<T> is not a type

    • C<T> is a template from which a type can be constructed

    • T is a formal type parameter

  • Constructed type

    • The type constructed from a template

    • C<int>, C<string>, and D<C<int>>

    • int, string, and C<int> are actual type parameters of C and D

The ability to have generic types is known as parametric polymorphism