#697 – Encapsulation is Managed through the Use of Access Modifiers

Encapsulation is one of the core principles of object-oriented programming.  Encapsulation is the idea of hiding implementation details of a class from the users of that class and only exposing a public interface.

When you author a class in C#, you can decide which class members (e.g. properties, fields, methods, events, etc) are visible to users of the class.  You do this by using access modifiers to indicate the accessibility of each class member.

Making some class members private allows hiding data from the users of the class, which supports the principle of encapsulation.  Encapsulation is also achieved by preventing access to methods whose use are internal to the code in the class.