Any reason to use auto-implemented properties over manual implemented properties?

前端 未结 7 1217
Happy的楠姐
Happy的楠姐 2020-11-27 07:22

I understand the advantages of PROPERTIES over FIELDS, but I feel as though using AUTO-implemented properties over MANUAL implemented properties doesn\'t really provide any

相关标签:
7条回答
  • 2020-11-27 07:55

    I don't know about everybody else, but I tend to pause a moment to think what I should name my variables and functions so others can understand my code.

    So when I use auto-implemented properties, I only have to pause once.

    When I need a backing field I have to pause two times, so it slows down development a bit :)

    The way I do it is:

    1. Make it a private variable in the start
    2. Change it public auto-implemented if needed.
    3. Change it to backing field if I need some code in get or set.

    There is nothing wrong if different properties of a class are exposed differently.

    0 讨论(0)
提交回复
热议问题