Question Object Property question

Kane Jeeves

Active member
Joined
May 17, 2006
Messages
44
Programming Experience
5-10
I have an object with three properties, A, B, and C. If A = 1 and B = 2 (for ex. I set them from a db in the object's New routine.) and C is a Readonly property = A + B. Is the addition in C done when the object is being created, or only when the property C is accessed in code somewhere? Seems like it would be only when accessed, but I've learned that some things in .NET are counter-intuitive. :+)

TIA
 
It's done each time the property is accessed. That's not to say that the compiler won't perform a bit of magic here seeing as it's a simple 'mov' instruction. But for the purposes of this question you can trust that when you access C it will add A & B and return the result.
 
Thanks for the quick reply. My property "C" will actually pull in various values from a SQL table based on A and B, then execute a bunch of comparisons, then finally return a boolean. The object is used quite a bit, but the property C not nearly as much. So I was hoping the accessing of C wouldn't effect performance of the object.
 
Back
Top