Accessibility in C#
Accessibility in C#
Accessibility means controlling the visibility of the class or its members.
Accessibilities of class and its members is controlled using Access Modifiers.
There are five types of access modifiers in C# -
- Public – It is applicable to type and member and has no access restriction.
- Protected – It is applicable to member and is accessible from within the class or by derived class.
- Internal – It is applicable to type and member and is accessible from within the files in the same assembly.
- Protected Internal – It is applicable to member and it is accessible from within the class or derived class and also within the derived class from another assembly.
- Private – It is applicable to member and is only accessible within the class.
Let’s see one example -
class Person
{
int Id;
string Name;
private string DOB;
internal string Age;
protected string FirstName;
protected string LastName;
protected internal void DisplayDetails()
{
}
public string Name
{
get { return FirstName + " " + LastName; }
}
}
Important points to be kept in mind related to access modifiers in C# -
- Class is internal if no access modifier is provided.
- Members are private if no access modifier is provided.
- Private access is the least permissive access level.
- By default, interfaces are internal.
- Interfaces can be public or internal.
- Access modifiers cannot be applied to interface members.
About the Author

Topic Replies (0)
You might also like