C# Properties

Since I’m doing some C# programming recently, I thought I’d create a new category (C#) and explore some issues in that area. Many of these issues are probably due to my recent history as a Java programmer coupled with a certain unfamiliarity with C# idioms. I’m not sure how well established C# idioms are at this time, nor do I necessarily like the ones that are.

Let ms start with C# properties. I quite like the idea of properties especially as they group the set and get operations. In other words, the concept of a property is a first class feature rather than something which emerges from the presence of related setter and getter methods.

Now, the question I have is whether you should start with a simple public field and move to a property if more complex behaviour needs to be encapsulated or should you start with a private field and trivial property definitions. The problem is that property access remains distinct from field access at the bytecode level if I understand correctly. That means properties are good for source evolution but not so good for binary evolution. If you do start with a simple field and replace that later with a property, it means recompiling all users of the code. On the other hand, coding trivial property accessors is not terribly exciting either.

One Reply to “C# Properties”

Comments are closed.