473,410 Members | 1,916 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,410 software developers and data experts.

C# 'Correct way' type question.

Hi,

I have a property of my object 'IsValid'. In order to evaluate the status of
the object I have to invoke a method of some sort.

Can I invoke a Method from against the Get method of the property. This
private method sets a private variable, the value of which is then the
return value of the property....

OR

Not have a property 'IsValid' but have a public Method with a return value
.......

or should I be using some other technique ?

In general when should I use properties and when should I use a method with
a return value ( or an 'out' parameter for that matter ) ?

Thanks, Jon.
Sep 20 '06 #1
3 1014
It sounds like you're talking about a property, as "IsValid" sounds like it
refers to state rather than process. However, if there are multiple
conditions that must be met for "IsValid" to be true, you would use a
property and a get accessor method to do the calculations and return the
boolean state value.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer

A watched clock never boils.

"Bishman" <jo*************@btinternet.comwrote in message
news:el**************@TK2MSFTNGP02.phx.gbl...
Hi,

I have a property of my object 'IsValid'. In order to evaluate the status
of the object I have to invoke a method of some sort.

Can I invoke a Method from against the Get method of the property. This
private method sets a private variable, the value of which is then the
return value of the property....

OR

Not have a property 'IsValid' but have a public Method with a return value
......

or should I be using some other technique ?

In general when should I use properties and when should I use a method
with a return value ( or an 'out' parameter for that matter ) ?

Thanks, Jon.

Sep 20 '06 #2
Jon,

It's not always black and white. With validity it could really go
either way. But, without knowing anything else about your situation
I'm leaning towards a property simply because I think validity does
represent a logical attribute of your class. Of course, if determining
validity involves a lengthy calculation I would use a method instead.
Here's a link that may help you decide.

http://msdn2.microsoft.com/en-us/library/ms229054.aspx

Brian

Bishman wrote:
Hi,

I have a property of my object 'IsValid'. In order to evaluate the status of
the object I have to invoke a method of some sort.

Can I invoke a Method from against the Get method of the property. This
private method sets a private variable, the value of which is then the
return value of the property....

OR

Not have a property 'IsValid' but have a public Method with a return value
......

or should I be using some other technique ?

In general when should I use properties and when should I use a method with
a return value ( or an 'out' parameter for that matter ) ?

Thanks, Jon.
Sep 20 '06 #3
Thanks for that guys,

Based on the MS article I think a method may be what I need here as the
'IsValid' evaluation is relatively 'expensive' in this case.

Interesting Article !

Cheers.

Jon.
"Bishman" <jo*************@btinternet.comwrote in message
news:el**************@TK2MSFTNGP02.phx.gbl...
Hi,

I have a property of my object 'IsValid'. In order to evaluate the status
of the object I have to invoke a method of some sort.

Can I invoke a Method from against the Get method of the property. This
private method sets a private variable, the value of which is then the
return value of the property....

OR

Not have a property 'IsValid' but have a public Method with a return value
......

or should I be using some other technique ?

In general when should I use properties and when should I use a method
with a return value ( or an 'out' parameter for that matter ) ?

Thanks, Jon.

Sep 20 '06 #4

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

Similar topics

10
by: Dirk Vanhaute | last post by:
I have only small knowledge of c++, but I would like to compile the example in http://support.microsoft.com/kb/q246772/ HOWTO: Retrieve and Set the Default Printer in Windows I included "#include...
14
by: john.burton.email | last post by:
I've done some extensive searching and can't seem to find an answer to this - Is it correct to using "using" with templates, for example: using std::vector; Or do I need to specify the type...
7
by: WildHare | last post by:
If I have a class and I add it to an ArrayList and then want to access that class using using the index operator (e.g. ArrayList) the ArrayList returns a type "Object". I can cast the return to...
1
by: Flix | last post by:
When making c# programs, I usually write code like this: SomeType myType=null; void Init() { myType=new SomeType(); }
4
by: Earl T | last post by:
When I try to get the netscape version for version 7, I get the HttpBrowserCapabilities class returning the version as 5 and not 7. (see code and output below) CODE HttpBrowserCapabilities...
50
by: Shadow Lynx | last post by:
Consider this simple HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head>...
4
by: webEater | last post by:
everytime i test my websites in ie (which should be done seperately from ff) the console shows me the error and the line number. problem: it shows me the line number of the file of the error's...
1
by: kang jia | last post by:
hi currently i am editing signup page, when user enter deupicated NRIC and click signup, they will go to do_signuppage and read the error message and then after 5 seconds, they will be redirected...
1
by: kang jia | last post by:
hi when user entered particulars in signuppage and click" signup" button, i will direct them to do_signup.php. if say the NRIC is dupicate in datebase, i will redirect them back to signup page...
4
by: Bill Fuller | last post by:
I am trying to determine the type for ActiveControls using 3rd party controls (Infragistics in this case) during runtime and getting a rather odd return type at runtime for the UltraWinEditor. ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
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...
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,...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.