372
C# Default values for getter-only properties
This feature allows us to set default values for the getters. The getter-only property is read-only property. We can’t set a new value to this property.
Compiler reports an error: cannot be assigned at compile time, if we assign value explicitly.
C# Default value for getter-only property Example 1
Output
Rahul kumar [email protected]
Let’s see an example, what happen if we assign value explicitly.
C# Default value for getter-only property Example 2
Output
error CS0200: Property or indexer 'Student.Name' cannot be assigned to -- it is read only
Next TopicC# Expression Bodied Members