Lecture overview -- Keyboard shortcut: 'u'  Previous page: Another example of constraints -- Keyboard shortcut: 'p'  Next page: Generic structs -- 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 12 : 21
Object-oriented Programming in C#
Generic Types and Methods
Variance

A CheckAccount is a BankAccount

But is a Set<CheckAccount> a Set<BankAccount> ?

/user/normark/oop-csharp-1/sources/c-sharp/set/set-of-bank-accounts/app.csSets of check accounts and bank accounts.


 

  • Covariance

    • The set types vary in the same way as the element types

  • Contravariance

    • The set types vary in the opposite way as the element types

  • Invariance

    • The set types are not affected by the variations of the element types

C# 3.0 uses invariance