Properties : private, protected and public


Which one you like? A private property is always difficult to access. Protected properties are also not very easy to penetrate. But what about public?
On the road, in a station any one can move freely not bothering about getting disturbed.
In C#, these properties can well be handled by get{}, set{}.
The main thing to remember is, a private property can not be accessed from any other class. Protected one can be reached by related ones and the public is open.
Still it’s better practice to start with private fields and later making it public.
The advantages are many.
See the codes below, first the Bear class and its properties. Next, calling those properties and methods in a web page.

The Bear class and its properties and the Page behind code
The page looks like this


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s