Is a public getter and a private setter with same name possible in C#?
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; }
}
Yes it is possible, even with auto properties. I often use:
public int MyProperty { get; private set; }