What are the benefits of using properties internally?

后端 未结 5 704
猫巷女王i
猫巷女王i 2020-12-10 19:19

Encapsulation is obviously helpful and essential when accessing members from outside the class, but when referring to class variables internally, is it better to call their

5条回答
  •  囚心锁ツ
    2020-12-10 19:43

    The benefit would be in the cases where there was validation to be done on the Get or Set. This would be in one place and always called.

    As far as I know (from other questions asked on Stack Overflow) when the Getter simply returns the value the code generated is the same as for accessing the variable directly.

提交回复
热议问题