Examples from Chapter 6 (Inheritance) of Programming C# 12.0 (O'Reilly).
- Example 3. Feeling downcast
- Example 4. The as operator
- Example 5. The is operator with a declaration pattern
- Example 8. Deriving from a generic base class
- Example 9. Requiring a type argument to derive from the type it's applied to
- Example 10. A method accepting any Base
- Example 11. A method accepting any IEnumerable<Base>
- Example 12. Passing an IEnumerable<T> of a derived type
- Example 13. A method accepting any ICollection<Base>
- Example 14. Error: trying to pass an ICollection<T> with a derived type
- Example 15. Covariant type parameter
- Example 16. Class hierarchy with actual members
- Example 17. Comparing shapes
- Example 18. Contravariant type parameter
- Example 19. Changing an element in an array
- Example 20. Passing an array with derived element type
- Example 21. A class with a virtual method
- Example 22. Using a virtual method
- Example 23. Overriding virtual methods
- Example 24. Exploiting virtual methods
- Example 25. An override that narrows the return type
- Example 26. An abstract class
- Example 27. Abstract interface implementation
- Example 28. Base type version 1.0
- Example 29. Class derived from version 1.0 base
- Example 30. Base type version 1.1
- Example 31. Hidden versus virtual method
- Example 32. Avoiding warnings when hiding members
- Example 33. Hiding to change the signature
- Example 34. A static virtual property in an interface
- Example 35. Invoking static virtual interface members
- Example 36. A base type with overloads distinguished only by a value type constraint
- Example 37. Spelling out the effect of the
struct
constraint - Example 38. Invoking the two methods
- Example 39. Overriding one of two ambiguous-looking methods
- Example 40. Using the
default
constraint
- Example 44. No default constructor in derived class
- Example 45. Invoking a base constructor explicitly
- Example 46. Exploring construction order
- Example 47. Record inheritance
- Example 48. Instantiating derived record types
- Example 49. Deriving from a positional record
- Example 50. Passing a constant to a positional base record
- Example 51. Using a derived record that has made a mandatory base property optional
- Example 52. Passing positional base record arguments with an ordinary constructor
- Example 53. Making an optional base property class positional
- Example 54. Using
with
on a base record type - Example 55. Testing how
with
interacts with inheritance