Just4Fun CSharp - property access modifier usage

less than 1 minute read

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:

Here are some wrong access modifier usages:

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

SUN Jiangong

SUN Jiangong

A senior .NET engineer, software craftsman. Passionate about new technologies.