In C#, Encapsulation is a principle of wrapping data (fields) and code (methods and properties) together as a single unit. In object-oriented programming, Encapsulation is the first, and main principle that is required to protect the data members of an object.
Why Encapsulation is needed?
This concept is often used to hide the internal representation, or state, of an object from the outside, which helps to protect data from being corrupted.
How to implement Encapsulation in C#?
With the help of access specifies (public, private, protracted, etc.) we bind data members, methods, and properties that operate on it into a single unit. For an example: