C# Encapsulation
In an Object Oriented programming language, encapsulation is one of the key language features. Encapsulation is the procedure of encapsulating data and functions into a single unit. The unit can be a class, a record, or a struct. If you're unfamiliar with OOP, please read Object Oriented Programming In C# (c-sharpcorner.com).
What is encapsulation in OOP?
Encapsulation in object-oriented programming (OOP) is a mechanism of hiding the internal details (implementation) of an object from other objects and the outside world. It is one of the four fundamental principles of OOP, along with inheritance, polymorphism, and abstraction. Encapsulation allows an object to control access to its data and methods, which can improve the security and stability of the system. In OOP, encapsulation is typically achieved through the use of access modifiers, such as "private" and "protected," which restrict access to certain members of a class.
Why do we need encapsulation?
Encapsulation is an important concept in object-oriented programming (OOP) because it allows you to hide the internal details (implementation) of an object from other objects and the outside world. This provides a number of benefits, such as:
Abstraction: Encapsulation allows you to create a level of abstraction between the internal workings of an object and its external behavior. This makes it easier to understand the code and reduces the risk of errors caused by changing the internal data directly.
Modularity: Encapsulation allows you to create self-contained objects that can be reused and combined in different ways. This makes your code more modular and easier to maintain.
Security: Encapsulation allows you to control access to the internal data of an object, which can improve the security of the system by preventing unauthorized access or modification of sensitive data.
Flexibility: Encapsulation allows you to change the internal implementation of an object without affecting the rest of the system. This makes your code more flexible and adaptable to changing requirements.
Extensibility: Encapsulation allows you to create a stable and robust system, as it allows you to add new features and functionality to the objects without affecting the existing code.
In summary, encapsulation makes the code more maintainable, flexible, and secure by providing a way to control access to the internal data of an object, creating a level of abstraction, and making the code more modular.
Encapsulation in C#
In C#, encapsulation is achieved through the use of access modifiers, such as "private," "protected," and "internal."

Mukesh KumarPosted Nov 19, 2015, 1:34 AM
Thanks to all
Anish AnsariPosted Nov 12, 2015, 8:37 AM
Nice
Raja TPosted Nov 12, 2015, 2:55 AM
Good,Thanks for sharing
Ranjit PowarPosted Nov 11, 2015, 11:07 PM
nice article
Former memberPosted Nov 11, 2015, 3:02 AM
Hi Mukesh you explain well. But, this article should be more clear about encapsulation and abstraction. You combined both. People will be not able to understand their individual purposes. Please go through the below link for the clear understanding of Encapsulation and Abstraction: http://stackoverflow.com/questions/8960918/how-encapsulation-is-different-from-abstraction-as-a-object-oriented-concept-in
Santhakumar MunuswamyPosted Nov 11, 2015, 2:35 AM
Good one
Sibeesh VenuPosted Nov 11, 2015, 12:37 AM
Nice Share
Manas MohapatraPosted Nov 10, 2015, 11:28 AM
Nice Description. One thing you need to change your code snippet. If you see code snippet deeply it is missing space between two words like "privatevoidVolumePlus". Please correct it.
Suman VermaPosted Nov 10, 2015, 7:36 AM
Nice article
Rajeesh MenothPosted Nov 10, 2015, 5:35 AM
Nice One