public private property

S

Sunny

Hi,
I want to have a property, for which I want only the get part to be public,
but set to be private? is it possible, or I have to make only get public,
and make a private method to set the value of the underlying variable? I
need to capture setting the variable in order to fire event, but I do not
want to allow users of the class to set the property?

May I doble declare the property like:

public int MyProp {get { return myVar;}}
private int MyProp {set {myVar = value;}}

Thanks
Sunny
 
J

Jon Skeet

Sunny said:
I want to have a property, for which I want only the get part to be public,
but set to be private? is it possible, or I have to make only get public,
and make a private method to set the value of the underlying variable?

Alas, it's not possible at the moment - it will be in the next version
of C#.
 
S

Sunny

Thanks Jon, I guessed so :)

Btw, how can you be so fast :) I always wonder how fast you answer :)

Thanks again
Sunny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top