How can I create a public getter and a private setter for a property? Is the following correct?
public String Password
{
set { this._password = value; }
}
p
Yes, as of C# 2.0, you can specify different access levels for the getter and the setter of a property.
But you have the syntax wrong: you should declare them as part of the same property. Just mark the one you want to restrict with private
. For example:
public String Password
{
private get { return this._password; }
set { this._password = value; }
}