C# Properties

I am sure you would have used Properties if you have written a fairly large C# program. I too have. Many of them.

A word of caution about it though. Properties are methods, MSDN calls them special methods. Either way, they are functions. The stack is modified, variables are copied, function is executed, a value is returned and stack is modified again. All this to access one variable.

If you declare a member variable as private and give users complete access to it by using get and set properties, then it’s certainly a better idea to just remove the properties and give direct access to it. Imagine the number of function calls you will be saving.

Moreover, in debug mode, if you add a watch on a variable, the get property is executed every time to refresh the value of the variable. I know time constraints don’t hold while debugging, but yoy may manage to speeden up your debugging process by a itsy-bitsy amount.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: