Member-only story
Access Modifiers in C#
Access modifiers are keywords used to specify the declared accessibility of a member or a type.
The below are mentioned the access modifiers with it’s visibility and accessibility:
Public (public):
The most permissive access modifier, public allows a type or member to be accessed from any assembly or code that references it. Public members are part of the type’s public contract.
Example
public class Fruit
{
public int FruitColor;
public void getFruitColor()
{
/* ... */
}
}
Private (private):
The least permissive access modifier, private restricts access to the containing type only. Private members are not visible to other types or outside the current class.
Example
public class Fruit
{
private int FruitColor;
private void getFruitColor()
{
/* ... */
}
}
Protected (protected):
Members with the protected access modifier can be accessed within the containing class and by derived classes. They are not accessible outside of the class hierarchy.
Example
public class Fruit
{…