Encapsulation C# newbie

前端 未结 5 981
我在风中等你
我在风中等你 2021-01-02 22:54

New to C#, and I understand that encapsulation is just a way of \"protecting data\". But I am still unclear. I thought that the point of get and set accessors wer

5条回答
  •  庸人自扰
    2021-01-02 23:12

    Yeah, but you can easily change it to:

    public string MyName { get; private set; }
    

    Plus, properties are used in other scenarios, like DataContracts and Serialization... so, this is a nice feature... (Mostly, syntactic sugar. I think) EDIT: I take that back.. you can apply virtual to it, so it's not the same

提交回复
热议问题