Different between properties and encapsulation in C#
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Aravind GovindarajRank #430 · 5.8K reputationPosted Oct 31, 2022, 7:55 AM EDT
Properties are one which is entities under the Class. For an instance. If you are getting if you are working with Employee object. Under the employee, you may have id, name, age, and address, those are all part of properties which exposed to outside to do get or set operation.
Encapsulation is one which is not exposed outside the world. For instance, the property, method which is using private accessor and does its operation internally and is not available outside the scope.
Real-Time example
Remote Control is an object
Buttons is property which is public property so its available outside scope
Connectors, IC are property however which is not available outside which acts as an encapsulation.
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Oct 31, 2022, 7:57 AM EDT
Properties enable a class to expose a public way of getting and setting values, while hiding implementation or verification code. A get property accessor is used to return the property value, and a set property accessor is used to assign a new value.
As in encapsulation, the data in a class is hidden from other classes, so it is also known as data-hiding. Encapsulation can be achieved by: Declaring all the variables / methods in the class as private and using C# Properties in the class to set and get the values of variables.