Read-only automatic property
I got a question during my latest presentation about automatic properties (full name is actually automatically implemented properties) with just a ‘getter’. I could not remember the syntax, thought it was something with the readonly keyword. I was wrong, here’s the correct syntax.
Note that this does have a setter, although it’s set to private. The reason is that it’s otherwise impossible to actually set the Title of the training. Normally we would set the backing field ‘_title’, but as this is generated by the compiler, we can’t access it yet.
The equivalent is:
Note that the private setter is still there. You can remove it completely and set the backing field as explained.