I suppose in a very broad sense you could regard 'namespaces' as a form of encapsulation.
To access types defined in the namespace, you either have to 'import' it (with the 'using' directive) or use the fully qualifed name of the type (i.e. namespace.type).
Other than that I can't think of any other form of encapsulation within C#. Did you have something else in mind?
Interfaces provide polymorphism rather than encapuslation.
However, as I intimated in your thread about private classes, when members of an interface are implemented explicitly this does achieve a level of encapsulation (in the 'hiding functionality' sense). This is because the method isn't marked ''public' and the caller therefore needs to be aware that you need an interface reference (not a reference to an object of the class itself) to call the method.
In contrast properties normally achieve encapsulation by hiding data (i.e. their backing fields).
Kavita BPosted Mar 29, 2011, 9:45 PM
Thanks a lot,i`m just a beginner need to know many things,sometimes my questions may not be clear so please don`t mind...
VulpesPosted Mar 29, 2011, 7:46 AM
Kavita BPosted Mar 29, 2011, 7:35 AM
Thanks for replying..Can encapsulation be implemented in any other way apart from what as been discussed till now???
VulpesPosted Mar 29, 2011, 4:58 AM
However, as I intimated in your thread about private classes, when members of an interface are implemented explicitly this does achieve a level of encapsulation (in the 'hiding functionality' sense). This is because the method isn't marked ''public' and the caller therefore needs to be aware that you need an interface reference (not a reference to an object of the class itself) to call the method.
In contrast properties normally achieve encapsulation by hiding data (i.e. their backing fields).
Kavita BPosted Mar 28, 2011, 9:49 PM
Are interfaces also used for the same?
Mahesh ChandPosted Mar 28, 2011, 9:33 PM