What does the “private” modifier do?

前端 未结 13 984
予麋鹿
予麋鹿 2021-01-17 07:24

Considering \"private\" is the default access modifier for class Members, why is the keyword even needed?

13条回答
  •  南笙
    南笙 (楼主)
    2021-01-17 07:46

    Explicitness. I never use the default and always explicitly add the modifier.

    This could be because of my Java background where the default was 'package' (roughly equivalent to 'internal' in C#) and so the difference always bothered me. I found explicitness to be preferable.

    I also use ReSharper now which defaults to being explicit, so it only confirms and reinforces my bias :)

提交回复
热议问题