CSharp - property acess modifier usage

/*By Jiangong SUN*/


I've found some points to pay attention when revising the access modifiers for properties in CSharp.

1. The access modfiers from higher to lower hierarchy are the following: public > protected internal > protected or internal > private

2. A property's modifier's hierarchy must be higher than its getter and setter.

3. A property's getter and setter can both have access modifier at the same time.

4. A private property's getter and setter can't have a access modifier.


Here are some correct access modifier usages:

CSharp - property acess modifier usage_第1张图片



Here are some wrong access modifier usages:


CSharp - property acess modifier usage_第2张图片


I hope this post do help to you! Enjoy coding!



你可能感兴趣的:(C#,property)