473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

What is the set on Properties?

Hi,

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.

Nov 15 '05 #1
3 1061
OK, you're wrong.

The property cannot be assigned without the set. Without it the property is
readonly.

This should be enough information to answer the rest of your question.
HTH
Brian W

"light_wt" <li*************@hotmail.com> wrote in message
news:01****************************@phx.gbl...
Hi,

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.

Nov 15 '05 #2
light_wt wrote:
Correct me if I am wrong. The property can be assigned
without the set portion.
That is incorrect. Without the set, you have a readonly property.
May be readonly visibility for derived classes?
*And* the base classs as well.
Why
is the benifit to have a readonly property in a class?


That's entirely up to the designer.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 15 '05 #3
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
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Pavils Jurjans | last post by:
Hallo, I yesterday was browsing the book, JavaScript The Definitive Guide (4th ed), which is, unquestionably, the best reference book for JS. To my surprise, I didn't find any documentation...
6
by: WindAndWaves | last post by:
Hi Folks I have inhereted a script that I understand reasonably well, I just do not understand !/^\d+$/.test(el.value) what the hell does that mean? Below is the script (there are really...
9
by: Mark Jones | last post by:
This rather cryptic title is actually a .net oop noob question. Example: My customer object has a public property called .name which is a string. I would like to be able to reference...
12
by: Perre Van Wilrijk | last post by:
Hi there, When I started using VB6, I used to write classes with properties and functions as following ... Private lngf1 As Long Private strf2 As String Public Property Get f1() As Long...
4
by: GS | last post by:
Hi, I'd rather start from a good design and go from there so would be greatfull for any input. I have a simple ASP.NET application and would like to make solution elegant. I store settings in...
7
by: Oleg Subachev | last post by:
What is C#'s analogue of Delphi's TAction ? If there is no one, how to implement the same functionality > Oleg Subachev
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
5
by: Cylix | last post by:
this.menus = { root: new Array };
9
by: pamelafluente | last post by:
Hi, I was "studying" the famous (public code) BusyBox. I see the instruction: var busyBox = new BusyBox as in var busyBox = new BusyBox("BusyBox1", "busyBox", 4, "gears_ani_", ".gif",...
3
by: shapper | last post by:
Hello, In my Page's VB.NET code I am changing the value of the Profile property NAME. Profile.Name = tbName.Text However, I need to change this property value from a class in my App_Code...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.