Different between properties and encapsulation in C#
Loading
Different between properties and encapsulation in C#
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rajanikant HawaldarPosted Oct 31, 2022, 11:57 AM
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.
Aravind GovindarajPosted Oct 31, 2022, 11:55 AM
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.