Property vs Attribute
-
In C++, I would declare my data values as private members with public get/set methods. I can do the same thing in C#, but I can also use properties. Any guideance on when to use one vs the other? Is there any performance/size difference? Thanks Chris Hafey
-
In C++, I would declare my data values as private members with public get/set methods. I can do the same thing in C#, but I can also use properties. Any guideance on when to use one vs the other? Is there any performance/size difference? Thanks Chris Hafey
Properties basically accomplish the same thing. Each propert should have an accompanying private field for the actual value. The only advantage is that you can do this :- abc.val = whatever; Nish
The rumours that I am an AI bot are absolutely false. These rumours have been propogated by *them* to focus all the attention on to me, while *their* bots take over the planet. Thank y%%%% Divide by zero. Cannot proceed. Abort(y/y)?
-
In C++, I would declare my data values as private members with public get/set methods. I can do the same thing in C#, but I can also use properties. Any guideance on when to use one vs the other? Is there any performance/size difference? Thanks Chris Hafey
You should use properties when you are dealing with storing the data in a private variable. You should use Get/Set methods when that data is NOT being stored cannot be accessed as quickly as a "return myPrivateData;". Some applications of this type would be retreive the customer name from the database; return all the prcoesses running on the system, etc... The line is a fine one and its quite elastic so just go with what feels right :) James Simplicity Rules!
-
In C++, I would declare my data values as private members with public get/set methods. I can do the same thing in C#, but I can also use properties. Any guideance on when to use one vs the other? Is there any performance/size difference? Thanks Chris Hafey
Stick with Properties when appropriate. The Property Grid likes them, the debugger likes them, and Serialization likes them. Go with the flow, it will make your life easier... Regards