I try to implement singleton
public static readonly MyClass Instance { get; } = new MyClass();
However Visual Studio tells me, I cannot use readonly for this item. Why is that?
I try to implement singleton
public static readonly MyClass Instance { get; } = new MyClass();
However Visual Studio tells me, I cannot use readonly for this item. Why is that?
readonly
is a valid modifier for fields.
For properties you can control if and who can write/read with get
and set
. readonly
doesn't make sense on a property.