Examples from Chapter 6 (Inheritance) of Programming C# 10.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 37. No default constructor in derived class
- Example 38. Invoking a base constructor explicitly
- Example 39. Exploring construction order
- Example 40. Record inheritance
- Example 41. Instantiating derived record types
- Example 42. Deriving from a positional record
- Example 43. Passing a constant to a positional base record
- Example 44. Using a derived record that has made a mandatory base property optional
- Example 45. Passing positional base record arguments with an ordinary constructor
- Example 46. Making an optional base property class positional
- Example 47. Using
with
on a base record type - Example 48. Testing how
with
interacts with inheritance