| Author: Jyoti Sharma 01 Aug 2006 | Member Level: Gold | Rating: Points: 2 |
The difference between a field and a property is that a field's value can be set directly. A property has a get and set method for getting and setting field data. There are several reasons why you might use a property instead of a field. You may want to do additional processing, or fire an event, when the value of a property changes. The property's set method can contain any additional code you want to execute when you set the value. You may want to check the value being assigned to a field prior to allowing the programmer to set it. This can also be done in a property, but not in a field. In the case of ViewState properties, you are exposing a ViewState member via a property whose set and get methods access ViewState and check to see whether the value is null or not, and can return a default value if it is null. There are other reasons as well, such as external dependencies, which may require a property rather than a field for some reason, etc.
Bottom line is, if you need any additional processing when setting or getting a value, make it a property. Otherwise, you may be wasting cycles.
|
| Author: Prem Kumar.O.M. 01 Aug 2006 | Member Level: Gold | Rating: Points: 2 |
Hi Public variables are technically called as fields.
If you have VS.NET Help, just go through this link
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_csref/html/f7f67b05-0983-4cdb-96af-1855d24c967c.htm
else go thru the below links
http://discuss.fogcreek.com/dotnetquestions/default.asp?cmd=show&ixPost=5814
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vbconPropertyProceduresVsPublicVariables.asp
Regards Prem
|