Is a public getter and a private setter with same name possible in C#?

前端 未结 6 1489
陌清茗
陌清茗 2021-02-06 21:29

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         


        
6条回答
  •  粉色の甜心
    2021-02-06 22:14

    public String Password
    {
        private set { this._password = value; }
        get { return this._password; }
    }
    

    or you can use an auto-implemented property:

    public String Password { get; private set; }
    

提交回复
热议问题