Access Modifiers in C# with Program Examples
Learn about access modifiers in C# such as public, private, protected and internal, with practical examples.
What are Access Modifiers?
Access modifiers are keywords that control the visibility and accessibility of classes, methods, and other members from other parts of a program.
public and private
The public modifier makes a member accessible from anywhere, while private restricts access to only within the same class, which is the most restrictive option.
protected and internal
The protected modifier allows access within the class and its derived classes, while internal restricts access to code within the same assembly.
Combining Modifiers
C# also allows combined modifiers like protected internal and private protected, giving finer control over how a member can be accessed across classes and assemblies.
.png)