Is it possible to create a set property which has a different accessibility
than the get property?
For example, I have a private field in a base class. The Get property should
be public so that anyone can see the value of the field. However the Set
property should be protected and non-overridable (since it does various
additional calculations/actions based on the new value) and only derived
classes should be able to Set a new value.
Hope that makes sense,
Thanks in advance for any help,
Ann-Marie Ratcliffe 9 1267 Is it possible to create a set property which has a different accessibility than the get property?
No. But it's a commonly requested feature for future versions.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Figures ;(
I guess the best work-around is to have the Property as read-only for the
hoi-polloi, and then have a protected Method for the derived classes, but it
all seems like a two'n'eight for what could be so simple.
Thanks for your quick reply,
Yours,
Ann-Marie Ratcliffe
P.S. If there is a neater way than I've suggested above I'd love to hear it.
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:OQ*************@TK2MSFTNGP11.phx.gbl... Is it possible to create a set property which has a different
accessibilitythan the get property?
No. But it's a commonly requested feature for future versions. Mattias
-- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ Please reply only to the newsgroup.
A Ratcliffe <ar********@archiNOSPAMmagic.net> wrote: I guess the best work-around is to have the Property as read-only for the hoi-polloi, and then have a protected Method for the derived classes, but it all seems like a two'n'eight for what could be so simple.
Yes, it's a pain - and frankly, I'm surprised it's one which didn't get
fixed before v1.0. It seems such an obvious thing to want to do...
maybe there are problems with it that I'm not aware of.
Having either a readonly property and a mutator method, or vice versa
(private property, public accessor), or just having two methods are
indeed the options at the moment.
Fortunately, not only has this been requested for the next version, but
apparently it's going to happen, too :)
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Thanks for the reassurance. I hope .NET Framework 1.2 comes soon.
Yours,
Ann-Marie Ratcliffe
PS. As noted in an earlier message, congratulations on your MVP status. One
day I hope to gain that honour, but somehow I think I've got a lot to learn
and much help to give before I see the light at the end of the tunnel.
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP***********************@msnews.microsoft.co m... A Ratcliffe <ar********@archiNOSPAMmagic.net> wrote: I guess the best work-around is to have the Property as read-only for
the hoi-polloi, and then have a protected Method for the derived classes,
but it all seems like a two'n'eight for what could be so simple.
Yes, it's a pain - and frankly, I'm surprised it's one which didn't get fixed before v1.0. It seems such an obvious thing to want to do... maybe there are problems with it that I'm not aware of.
Having either a readonly property and a mutator method, or vice versa (private property, public accessor), or just having two methods are indeed the options at the moment.
Fortunately, not only has this been requested for the next version, but apparently it's going to happen, too :)
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
A Ratcliffe <ar********@archiNOSPAMmagic.net> wrote: Thanks for the reassurance. I hope .NET Framework 1.2 comes soon.
I don't know what version number Whidbey will be, but I suspect it'll
be v2.0, given the number of big enhancements (eg generics) to it.
Unfortunately, I don't think it'll be here for a while :(
PS. As noted in an earlier message, congratulations on your MVP status. One day I hope to gain that honour, but somehow I think I've got a lot to learn and much help to give before I see the light at the end of the tunnel.
Fortunately I've found that learning and giving help go hand in hand :)
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
I believe this is more issue of c# than of .NET as a platform. So hopefully
the next version of the compiler will let us to that.
B\rgds
100
"A Ratcliffe" <ar********@archiNOSPAMmagic.net> wrote in message
news:u4**************@TK2MSFTNGP11.phx.gbl... Thanks for the reassurance. I hope .NET Framework 1.2 comes soon.
Yours,
Ann-Marie Ratcliffe
PS. As noted in an earlier message, congratulations on your MVP status.
One day I hope to gain that honour, but somehow I think I've got a lot to
learn and much help to give before I see the light at the end of the tunnel.
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP***********************@msnews.microsoft.co m... A Ratcliffe <ar********@archiNOSPAMmagic.net> wrote: I guess the best work-around is to have the Property as read-only for the hoi-polloi, and then have a protected Method for the derived classes, but it all seems like a two'n'eight for what could be so simple.
Yes, it's a pain - and frankly, I'm surprised it's one which didn't get fixed before v1.0. It seems such an obvious thing to want to do... maybe there are problems with it that I'm not aware of.
Having either a readonly property and a mutator method, or vice versa (private property, public accessor), or just having two methods are indeed the options at the moment.
Fortunately, not only has this been requested for the next version, but apparently it's going to happen, too :)
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
100 <10*@100.com> wrote: I believe this is more issue of c# than of .NET as a platform. So hopefully the next version of the compiler will let us to that.
No, it's part of .NET itself - the CLI specification itself currently
states that a property must have the same access for access as
modification, although I can't remember exactly where.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Yes you are right
"CLS Rule 25: The accessibility of a property and of its accessors shall be
identical."
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... 100 <10*@100.com> wrote: I believe this is more issue of c# than of .NET as a platform. So
hopefully the next version of the compiler will let us to that.
No, it's part of .NET itself - the CLI specification itself currently states that a property must have the same access for access as modification, although I can't remember exactly where.
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Different property accessors are allowed in Managed C++, the restriction is at the CLS level.
Willy.
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP************************@msnews.microsoft.c om... 100 <10*@100.com> wrote: I believe this is more issue of c# than of .NET as a platform. So hopefully the next version of the compiler will let us to that.
No, it's part of .NET itself - the CLI specification itself currently states that a property must have the same access for access as modification, although I can't remember exactly where.
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Generic Usenet Account |
last post by:
A lot has been said in this newsgroup regarding the "evil" set/get
accessor methods. Arthur Riel, (of Vanguard Training), in his class,
"Heuristis for O-O Analysis & Design", says that there is...
|
by: Gary Morris |
last post by:
Hello all,
OK, first of all I have known about properties since VB6, which
I have and have used extensively. It seems that property get
and set are basically the same concept in C# and VB.NET,...
|
by: Peter Cresswell |
last post by:
Hello everyone,
I would like to serialize an object to XML. Currently my code will serialize
all of the public properties that are value types, but not my public
properties that have get...
|
by: Joe Fromm |
last post by:
Perhaps I'm missing something obvious, but I've been curious about one of
the coding practices I see advocated. I'm a longtime C/C++ programmer
trying to learn C#, and I started looking around for...
|
by: Brett |
last post by:
If I do this without declaring a corresponding field, is it considered bad
design? What are the advantages or disadvantages to either method? Notice
there is not set.
public string URL
{
get...
|
by: VMI |
last post by:
WHy are the get/set properties so useful? I know they're used so that I don't
directly access a variable, but why is that so useful? What would the
difference be between using it directly and using...
|
by: Jon Slaughter |
last post by:
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
In the above, why doesn't C# just allow one to create a single directive to
make a property?
|
by: Artur Siekielski |
last post by:
Hi.
I would like to have declarative properties in Python, ie. something
like slots definitions in defclass in Common Lisp. It seems that even
Java will have it, using a library (...
|
by: FullBandwidth |
last post by:
I have been perusing various blogs and MSDN pages discussing the use
of event properties and the EventHandlerList class. I don't believe
there's anything special about the EventHandlerList class in...
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |