Readonly struct members
Following the introduction of the readonly
struct in C# 7, it is now possible to specify the readonly
modifier singularly on its members. This feature has been added for all those cases where the struct type cannot be entirely marked as read-only, but when only one or more members can guarantee not to modify the state of the instance.
The main reason why I love this feature is because expressing the intents explicitly is a best practice in terms of maintenance and usability.
It is also important from a performance perspective because the readonly
struct provides a sort of hint to the compiler, which can apply better optimizations. The modifier can be applied on fields, properties, and methods to guarantee it does not mutate the struct instance, but does not give any guarantee on the referenced objects.
When dealing with properties, the modifier can be applied on the property or on just one of the accessors:
public readonly int Num0 { ...