Private Set or Private member?

前端 未结 7 2204
旧时难觅i
旧时难觅i 2020-12-29 05:05

I was wondering what\'s considered the C# best practice, private/protected members with public getters, or public getters with private/protected setters?

            


        
7条回答
  •  被撕碎了的回忆
    2020-12-29 05:34

    There's nothing wrong with private setters. In most case, it's used with auto properties to make the property readonly outside the object's scope.

提交回复
热议问题