light_wt <li*************@hotmail.com> wrote:
I have a simple question about methods property. The
syntax is
public <dataType> MtdName{
get {
// property get code
}
set {
// property set code
}
}
Correct me if I am wrong. The property can be assigned
without the set portion. So, what does the set exactly
do? May be readonly visibility for derived classes? Why
is the benifit to have a readonly property in a class?
Thanks.
No, the property can't be assigned to without the set portion. The set
portion does whatever you tell it to do.
You can't currently give different accessibility to the get and set
portions, unfortunately.
The benefit of making a readonly property is that you don't need to
worry about users changing the values - it may not even make *sense* to
allow them to change them. For instance, what sense would it make to
allow a user to change the value of Encoding.ASCII, or Int32.MaxValue?
Immutable types are very handy - and they *must* be read-only, by
definition.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too