1. Private Modifier
The private modifier is used to set the access permission of a class or class member to the internal of the class,
Private is also called a private modifier. You can use the get and set accessors to read or modify private class members.
2. Protected Modifier
The protected modifier is used to set the access permissions of a class or class member to the class and its subclass.
3. Internal Modifier
The access permission of the class or class member modified by internal modifier is within the same assembly, and the default class access modifier of C # is internal.
4. Public Modifier
The public modifier is the public access permission, which has no restrictions on code access,
In most cases, you must exercise caution when using the public modifier because misuse affects the encapsulation of classes and brings security risks.
Declared accessibility |
Meaning |
Public |
Unrestricted access |
Protected |
Access is limited to include classes or types derived from include classes |
Internal |
Access is limited to the current project only |
Protected internal |
Access is limited to the current project or type derived from the include class. |
Private |
Access is limited to include type only |