Accessor access modifiers

  • Thread starter Thread starter Ben R. Bolton
  • Start date Start date
B

Ben R. Bolton

Is it possible to define a property such that the get accessor is public and
the set accessor is private?

Ben
 
This is what seems wierd to me. If yo have a private set property why even
have it at all. why not just use the member variable. your basically sayign
i need to access a member in a class from within the same class but not
anywhere else. It seems a waste to me to write methods and properties for
something like this.
 
When a dog is hungry it whines.

Dog dog = new Dog();
dog.IsHungry = true;

It won't start whining if "IsHungry" is just a field! Solution - make it a
property and invoke Dog.Whine() in the setter. :))
 
Back
Top