Question Property evaluation

Kane Jeeves

Active member
Joined
May 17, 2006
Messages
44
Programming Experience
5-10
I'm trying to decide whether to get a value, call it X, in my class through a read only property or through a function. Normally I'd code it as a property except in this case the GET involves doing a lookup to a sql table. So there's way more overhead than a simple RETURN X.

So my question is, when I instantiate a new object from my class, are all the properties calculated at that point, so that the sql lookup will occur too? Or is the property only evaluated when I actually reference it in the calling code.

Thanks!
 
According to Choosing Between Properties and Methods it should be a method.

The code in property getter is executed when called in code, or asked for in interactive debugging as mentioned, not when class instance is constructed.
 
Back
Top