LibertyOrDeath
June 20th, 2009, 08:35 AM
Hi all,
This is a general question. I'm currently teaching myself C# from a textbook so I'm a relative newbie to the language, although I already know Java and C++ so I'm not finding it too difficult to pick up.
I've just covered a section on properties for objects. The book says that access modifiers may be specified for either the set or get accessor of a property, where the access modifier must be more restrictive than that of the property itself, i.e.
public int MyProperty
{
protected get
{
// Do something
}
set
{
// Do something else
}
}
The book says that an access modifier can be specified for either set or get but not both. It doesn't explain why this is the case though. Why can't it be both? What was the rationale for this rule when C# was created? What are the benefits of this restriction?
This is a general question. I'm currently teaching myself C# from a textbook so I'm a relative newbie to the language, although I already know Java and C++ so I'm not finding it too difficult to pick up.
I've just covered a section on properties for objects. The book says that access modifiers may be specified for either the set or get accessor of a property, where the access modifier must be more restrictive than that of the property itself, i.e.
public int MyProperty
{
protected get
{
// Do something
}
set
{
// Do something else
}
}
The book says that an access modifier can be specified for either set or get but not both. It doesn't explain why this is the case though. Why can't it be both? What was the rationale for this rule when C# was created? What are the benefits of this restriction?