Use of properties vs backing-field inside owner class

Posted by whatispunk on Stack Overflow See other posts from Stack Overflow or by whatispunk
Published on 2010-03-16T18:21:43Z Indexed on 2010/03/16 18:31 UTC
Read the original article Hit count: 201

I love auto-implemented properties in C# but lately there's been this elephant standing in my cubicle and I don't know what to do with him.

If I use auto-implemented properties (hereafter "aip") then I no longer have a private backing field to use internally. This is fine because the aip has no side-effects. But what if later on I need to add some extra processing in the get or set?

Now I need to create a backing-field so I can expand my getters and setters. This is fine for external code using the class, because they won't notice the difference. But now all of the internal references to the aip are going to invoke these side-effects when they access the property. Now all internal access to the once aip must be refactored to use the backing-field.

So my question is, what do most of you do? Do you use auto-implemented properties or do you prefer to always use a backing-field? What do you think about properties with side-effects?

© Stack Overflow or respective owner

Related posts about properties

Related posts about auto-implemented-propert