Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
1.14/5 (5 votes)
See more:
give full explanation of public private and protect....why it can be used.....
and give some example program



thanks
Posted
Comments
Matt T Heffron 10-Oct-13 13:59pm    
http://lmgtfy.com/?q=c%23+private+public+protected
idenizeni 10-Oct-13 14:00pm    
This looks like a question copied from a school assignment.

http://msdn.microsoft.com/en-us/library/ms173121.aspx

Try starting here Access Modifiers (C# Reference)[^].
 
Share this answer
 
Well,before referring something i can say you about my thoughts about those terms.
Literally these terms are called Access Modifiers.When you declare something public, the class (and consequently the object) is making a strong statement: this is my visible interface, there are many other like this but this is mine. The public interface is a contractual agreement that your class is exporting to the rest of the world (whatever that means) about what it can do. If you modify the public interface, you risk to break the contract that the rest of the world is assuming about the class.

On the other hand, private stuff is internal to the class. It is support functionality that the class must use in order to do its job, while carrying the object state around (if it's a method) or keeping its internal state (if it's a variable). You are free to hack and tinker the class private stuff as much as you want, without breaking the interface contract, meaning that this gives you wide freedom for refactoring (of the internal data representation, for example, for efficiency). private stuff is not part of the interface.

Protected is something that involves the openness to reimplementation. Avoid, if you can, deeply nested inheritances. You risk to make things very difficult to handle, as the base class can be screwed by your reimplementation class.

Behind this,check some really good answers from CP that i like to refer here:
access modifiers in c#[^]

And,you can check also Accessibility Levels from it:
Accessibility Levels[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900