I've created an interface with some properties.
If the interface didn't exist all properties of the class object would be set to
{ get; private set; }
However, this isn't allowed when using an interface,so can this be achieved and if so how?
I've created an interface with some properties.
If the interface didn't exist all properties of the class object would be set to
{ get; private set; }
However, this isn't allowed when using an interface,so can this be achieved and if so how?
Interface defines public API. If public API contains only getter, then you define only getter in interface:
Private setter is not part of public api (as any other private member), thus you cannot define it in interface. But you are free to add any (private) members to interface implementation. Actually it does not matter whether setter will be implemented as public or private, or if there will be setter:
Setter is not part of interface, so it cannot be called via your interface:
In interface you can define only
getter
for your propertyHowever, in your class you can extend it to have a
private setter
-