I have a class with readonly fields that indicate the state of my object. These fields should be visible from the outside.
First, I showed these fields using propertiesas follows:
public class MyClass
{
private readonly MyState mystate = new MyState();
public MyState MyState { get { return this.mystate; } }
}
But since this readonly, users of my class cannot change the state instance. So I deleted my own property, set the field readonlyas publicand renamed it to Pascal Case.
So far, the only problem I have seen has been refactoring, but since mine public propertyis in a camel case, such as mine public readonly, I can easily move it to property.
Can Jimmy ruin my object (without changing the code), or is it safer to use property?
source
share