Examples from Chapter 3 (Types) of Programming C# 10.0 (O'Reilly).
- Example 6. Using static members normally
- Example 7. Using static members without explicit qualification
- Example 8. Plain old data, using public fields
- Example 9. Enforcing initialization of fields with a constructor
- Example 10. A record type with positional syntax
- Example 11. Using a record type
- Example 12. Making a modified copy of an immutable record
- Example 13. A record type with modifiable properties
- Example 14. Comparing two instances of a type
- Example 15. Nested record types
- Example 16. Using nested record types
- Example 17. Copying references
- Example 18. Comparing references
- Example 19. Comparing values
- Example 20. Specifying nullability
- Example 21. Specifying enabled nullable warning and annotation contexts as the project-wide default
- Example 22. Dereferencing a nullable reference
- Example 23. The null forgiving operator
- Example 24. Nullability and the Try pattern—before nullable reference types
- Example 25. Nullable-aware use of the Try pattern
- Example 26. A nullable attribute
- Example 27. Arrays and nullability
- Example 28. A simple struct
- Example 29. Support custom comparison
- Example 30. Comparing struct instances
- Example 31. A read-only struct
- Example 32. A read-only struct in a read-only property
- Example 33. A read-only
record
, a mutablerecord struct
and areadonly record struct
- Example 35. Error: failing to provide a Uri with its URI
- Example 36. A class with one constructor
- Example 37. Using a constructor
- Example 38. Record type with compiler-generated constructors
- Example 39. A nonempty zero-argument constructor
- Example 40. Record type with customized copy constructor
- Example 41. Optional chaining of constructors
- Example 42. Chained constructor arguments
- Example 43. Class with static constructor
- Example 44. Significant ordering of static fields
- Example 45. Initialization order
- Example 46. Circular static dependencies
- Example 47. Enabling deconstruction
- Example 48. Using a custom deconstructor
- Example 49. Positional pattern using a custom deconstructor
- Example 50. Positional pattern with explicit type
- Example 51. Record struct using positional syntax
- Example 52. Passing arguments by reference
- Example 53. Putting an out parameter's result into a new variable
- Example 54. Using out parameter's result in the same expression
- Example 55. Putting an out parameter's result into an existing variable
- Example 56. Discarding an out parameter's result
- Example 57. Calling a method with a ref argument
- Example 58. A large value type
- Example 59. A method with an in parameter
- Example 60. Calling a method with an in parameter
- Example 61. A local ref variable
- Example 62. Valid and invalid uses of ref returns
- Example 63. A method with optional arguments
- Example 64. Omitting one argument
- Example 65. Specifying an argument name
- Example 66. Unclear arguments
- Example 67. Improving clarity by naming arguments
- Example 68. Overloaded method
- Example 69. String formatting
- Example 70. Explicitly passing multiple arguments as an array
- Example 71. The params keyword
- Example 72. Local functions
- Example 73. An expression-bodied method
- Example 74. An extension method
- Example 75. Extension method available due to namespace declaration
- Example 76. Extension method available due to using directive
- Example 77. Class with simple property
- Example 78. Expression-bodied get and set
- Example 79. An auto-implemented property
- Example 80. Using a property
- Example 81. Auto-property with private setter
- Example 82. Auto-property with no setter
- Example 83. Initializing an auto-property with no setter
- Example 84. Record requiring initial values, but allowing later modification
- Example 85. Class with auto-property with init-only setter
- Example 86. Setting an init-only property
- Example 87. A read-only struct with init-only properties
- Example 88. Using the with syntax on a non-record read-only struct
- Example 89. A calculated property
- Example 90. An expression-bodied read-only property
- Example 91. A property using a mutable value type
- Example 92. Error: cannot modify a property of a value type property
- Example 93. Replacing a property with methods
- Example 94. A property returning a reference
- Example 95. Making the copy explicit
- Example 96. Making the reference explicit
- Example 97. Using an indexer
- Example 98. Class with indexer
- Example 99. Null conditional index access
- Example 100. Code equivalent to null-conditional index access
- Example 101. Using an object initializer
- Example 102. Using a constructor and an object initializer
- Example 103. Using an indexer in an object initializer
- Example 104. Implementing the + operator
- Example 105. Supporting other operand types
- Example 106. Conversion operators
- Example 107. Using explicit conversion operators
- Example 109. An interface
- Example 110. Implementing an interface
- Example 111. Explicit implementation of an interface member
- Example 112. An interface with a default property implementation
- Example 113. An interface with a const and a nested type