I pressed F12 by mistake on Point type and I saw something like:
public int X
{
readonly get => x;
set => x = value;
}
I’m not getting this, I know that X is not readonly here, also if it was going to be read-only there shouldn’t be a setter.
what does readonly get mean?
Can anybody tell me what the above getter and setter mean?
Update: from the link on Guru’s answer. it says:
Readonly can be applied to some auto-implemented properties, but it won’t have a meaningful effect. The compiler will treat all auto-implemented getters as readonly whether or not the readonly keyword is present.
if it has no effect, why to put it there in the first place.
>Solution :
Since C# 8 you can mark members of struct‘s as readonly to signify that they do not change it’s state. This is used to prevent hidden copies from happening in case of struct used with in modifier:
This normally doesn’t have much impact, except in the case of
inparameters. Withinparameters for non-readonly structs, the compiler will make a copy of the parameter for each instance member invocation, since it cannot guarantee that the invocation does not modify internal state.
For example as it used in System.Drawing.Point struct.
Read more in Readonly Instance Members specification.