473,508 Members | 2,330 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessor access modifiers

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

Ben
Nov 15 '05 #1
3 1399
Nope. Create a private method instead of setter.

"Ben R. Bolton" <xb*******@hotmail.com> wrote in message
news:OL**************@TK2MSFTNGP11.phx.gbl...
Is it possible to define a property such that the get accessor is public and the set accessor is private?

Ben

Nov 15 '05 #2
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.
"Val Savvateev" <vs********@meridium.com_NO_SPAM> wrote in message
news:eB**************@TK2MSFTNGP11.phx.gbl...
Nope. Create a private method instead of setter.

"Ben R. Bolton" <xb*******@hotmail.com> wrote in message
news:OL**************@TK2MSFTNGP11.phx.gbl...
Is it possible to define a property such that the get accessor is public

and
the set accessor is private?

Ben


Nov 15 '05 #3
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. :))
"Dave Quigley[work]" <dave at outta-sites dot com> wrote in message
news:en**************@tk2msftngp13.phx.gbl...
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.
"Val Savvateev" <vs********@meridium.com_NO_SPAM> wrote in message
news:eB**************@TK2MSFTNGP11.phx.gbl...
Nope. Create a private method instead of setter.

"Ben R. Bolton" <xb*******@hotmail.com> wrote in message
news:OL**************@TK2MSFTNGP11.phx.gbl...
Is it possible to define a property such that the get accessor is
public and
the set accessor is private?

Ben



Nov 15 '05 #4

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

Similar topics

22
6731
by: mirandacascade | last post by:
When I look at how classes are set up in other languages (e.g. C++), I often observe the following patterns: 1) for each data member, the class will have an accessor member function (a...
3
1735
by: kchalla | last post by:
Can anybody let me know the difference between public and private class access modifiers? Thanks in advance
2
2718
by: Bob Weiner | last post by:
Is it possible to create a property and specify different access modifiers for the get and set methods? From the property definition it appears that you can define attributes but not access...
11
1673
by: Kavvy | last post by:
How come a lot of the examples I have seen on the net define accessor pairs within a class, and then only ever use the accessor outside the class? When used within the class the variable is...
4
3195
by: Picho | last post by:
Hi all, Using reflection, I can invoke/call private methods of an object. is this intended? if yes, why? in what scenario (example would be good) should I be givven the option to use...
2
7699
by: Anders Borum [.NET/C# MCP] | last post by:
Hello! With C# 2.0 coming up, I was wondering what your thoughts are regarding the introduction of access modifiers on set accessors. Personally, I like the first example, because of its...
1
1852
by: Ashkan Daie | last post by:
Hi All, Is there an internal access modifier in managed vc++ like vc#? Thanks, Ashkan
2
1548
by: Vark | last post by:
Interesting behavior I came across today where a child form has full access to a base form class' controls, but you can only modify the controls' properties in code, not in the visual designer....
5
2469
by: TS | last post by:
is it preferred to access member variables directly in code, on the page that declared them, versus going thru a property accessor? I would think that since theres no security concerns or anything...
0
7233
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
7135
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...
0
7342
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,...
0
7410
jinu1996
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...
1
7067
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5650
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.