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
{
protected string FruitColorField;
}
public class Mango : Fruit
{
public void SetFruitColor()
{
FruitColorField = Yellow; // Access the protected field from the base class
}
}
Internal (internal):
The internal modifier allows access within the same assembly (or module) but not from outside assemblies. Types and members marked as internal can be seen and used by code in the same assembly.
Example
internal class MyInternalClass
{
internal int MyInternalField;
}
Protected Internal (protected internal):
The protected internal allows access within the containing class and by derived classes that are in the same assembly. It was introduced in C# 7.2. It restricts access outside the assembly.
Example
public class Fruit
{
protected…