- Calling a property twice should always returns the same value. Of course,
the value might change between first and second time, but not *due to
calling the property*. That's not true for functions.
- Retrieving a property should be "fast" (however you define "fast").
Always imagine watching the object in the local/watch window: Neither the
property value should change just by watching it, nor it should take 5 min.
to watch it (and lock the IDE).
Armin
"Matt Thompson" <matt.t...@sensonics.co.uk> schrieb:
> Whats the difference between having a function that returns
> a piece of data (a string or a structure) and a property that
> does the same?
Properties are used to model *attributes* of an object, functions are used
to model things, the object can *do*.
Calling Properties should not change the state of the object. A property
should return the same value if you call it twice (without any change on the
object in the meantime). Nevertheless, there are some cases where the value
can be different (current time, amount of data processed and so on).
If the calculation for the property value requires a lot of time, it's often
better to define a function, for example GetNumberOfClients.
Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
"Herfried K. Wagner" <aon.912666908.N.O.S.P.@.M.aon.at> wrote in message
news:eSki9h6R...@TK2MSFTNGP11.phx.gbl...
"Matt Thompson" <matt.t...@sensonics.co.uk> schrieb:
> Thanks (Herfield and Armin),
> Both yourself and Armin mentioned time as a factor, does a propertry get
> treated differently that means it's slower?
I expect a property to return the value quickly. There is no performance
difference between properties and functions. Nevertheless, I think the most
important point is that properties are used to model the object's
*attributes*.
You'll definetly want to look at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconpropertyusageguidelines.asp
Karl
"Matt Thompson" <matt.t...@sensonics.co.uk> wrote in message
news:%23u56xl6...@tk2msftngp13.phx.gbl...
No, it is not slower, but if the code takes longer to execute, you should
put it into a function instead of a property.
Armin
"Karl Seguin" <kseguin##crea.ca> wrote in message
news:%237yUeu6...@TK2MSFTNGP10.phx.gbl...