473,585 Members | 2,496 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 1403
Nope. Create a private method instead of setter.

"Ben R. Bolton" <xb*******@hotm ail.com> wrote in message
news:OL******** ******@TK2MSFTN GP11.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********@mer idium.com_NO_SP AM> wrote in message
news:eB******** ******@TK2MSFTN GP11.phx.gbl...
Nope. Create a private method instead of setter.

"Ben R. Bolton" <xb*******@hotm ail.com> wrote in message
news:OL******** ******@TK2MSFTN GP11.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******** ******@tk2msftn gp13.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********@mer idium.com_NO_SP AM> wrote in message
news:eB******** ******@TK2MSFTN GP11.phx.gbl...
Nope. Create a private method instead of setter.

"Ben R. Bolton" <xb*******@hotm ail.com> wrote in message
news:OL******** ******@TK2MSFTN GP11.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
6748
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 Get<whatever> function) 2) for each data member, the class will have a mutator member function (a Set<whatver> function) 3) data members are never referenced...
3
1742
by: kchalla | last post by:
Can anybody let me know the difference between public and private class access modifiers? Thanks in advance
2
2733
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 modifiers. I have never used attributes so I don't know if they are useful for this purpose. What I want to do is to create an 'Entry' class that will...
11
1689
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 accessed directly. Is there something I'm missing about this? To reduce code re-writing it is (I thought) standard practice to use accessor pairs in the...
4
3200
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 something that was declared private (not public) and not mine to use? seems to me this is somewhat malicious... if not.... well....
2
7703
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 simplicity. The second seems rather dangerous and the third one - well, quite verbose. I'm trying to communicate best practices to fellow developers...
1
1857
by: Ashkan Daie | last post by:
Hi All, Is there an internal access modifier in managed vc++ like vc#? Thanks, Ashkan
2
1551
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. Here's how you can reproduce it: New Winforms project On Form1, drop a visual control. I'll use a panel in this example. Make sure Panel1 modifier...
5
2471
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 it would be more efficient to access directly. I also don't think that you would need to do any special validation since the class developer knows...
0
7908
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7836
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
6606
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5389
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3835
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1175
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.