Fields don't scale well. You can't decide to add validation or special
behaviour to them later. Proxy code generators usually ignore them. You
can't convert one into a dependency property later. They won't appear in the
PropertyGrid control. They have different serialization behaviour. You can't
put different access modifiers on the get/set of a field.

 

You can use abbreviated property { get; set; } syntax, so why not do that
instead of using fields, and you'll get the possible benefits later. I doubt
if there is any performance difference between fields and properties (unless
anyone has news that this is an argument for using fields).

 

Greg

 

From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com]
On Behalf Of Jeff Sinclair
Sent: Wednesday, 25 August 2010 11:13
To: 'ozDotNet'
Subject: Properties

 

Can some one tell me why people get so worked up about all fields being
private and accessed only via properties.

If you have a class which is only used essentially as group of variables, eg
to put into a data structure like a tree or something then why not public
fields? 

Do all those properties really add any value?

 

Jeff

 

 

Reply via email to