The codebase I'm working in now has the convention of using private fields and public properties. For example, most classes have their members defined like this:
// Fields
private double _foo;
private double _bar;
private double _baz;
// Properties
public double Foo
{
get{ return _foo; }
set{ _foo = value; }
}
public double Bar
{
get{ return _bar; }
set{ _bar = value; }
}
public double Baz
{
get{ return _baz; }
}
I know these can be rewritten without their internal private properties:
public double Foo{ get; set; }
public double Bar{ get; set; }
public double Baz{ get; private set; }
I'd like some input on this:
- Is there a good reason to prefer the older, more explicit style over the newer, more concise one?
- Should I write any new classes using the concise style, or should I try to match the older code for consistency? Is consistency worth enough in this case to justify the older format?