On Fri, 18 May 2007 18:06:13 +0200, Claude Grecea <cg*****@shionogi-usa.comwrote:
Can someone please explain to me when you would use a Property instead of a
field and wy? Thanks in advance.
Hi Claude,
A few things that springs to mind
1) DataBinding requires a Property
2) Smart fields. Processing indata before storing it, or not storing data at all but generating the value when asked.
3) Better control over who can write to the property. You can have public getters and private setters.
4) Easier to change logic. You can rewrite the getter and setter without touching outside code.
I don't think I have exposed a class field for a long time, and rarely even use the fields other than as property storage. With C# 3.0 even property storage isn't needed in many cases.
--
Happy coding!
Morten Wennevik [C# MVP]