I'm currently thinking about encapsulating data in C #, and I'm a bit confused. A few years ago, when I began to study programming in C ++, my professor told me: - "Create a class and hide its data elements, so it cannot be manipulated directly from the outside"
Example: You parse an XML file and store the parsed data in some data elements inside the parser class.
Now when I look at C #. You have properties. This function makes the internal state / internal data of the class visible from the outside. No more encapsulation. Correctly?
private string _mystring; public string MyString { get {return _mystring;} set {_mystring = value;} }
From my point of view, there is no difference between posting data or public properties that getters and setters have, where you pass your personal data through.
Can someone please explain to me?
thanks
c # properties encapsulation member
Ferhat
source share