Best Practice on local use of Private Field x Property

后端 未结 9 1692
萌比男神i
萌比男神i 2021-01-22 02:09

When inside a class you have a private fiels and expose that field on a public property, which one should I use from inside the class?

Below you is an example on what I

9条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-22 02:52

    Use the private field because you are not doing something in specific in the setter.

    I would also recommend to remove the property-setter, this way you force the state of the counter to be set by the given method DoSomething()

提交回复
热议问题