View Single Post
  #129 (permalink)  
Old 12-26-2007, 05:12 AM
arjkhanna arjkhanna is offline
D-Web Genius
 
Join Date: Mar 2007
Posts: 1,102
arjkhanna is on a distinguished road
Default Re: ASP.NET Data Controls

what are the differences between property and local variable in

C#???

The Local variable defined inside the class adds up to the state

definition of the object during runtime, So when I say any object is in

valid state I necessarily mean that every member/local field of the class

has it's value in the desired and appropriate state. A property is the

interface provided for the outside world to access any particular field of

the class to manipulate the object state in the controlled way.

That's why it's the standard practice to encapsulate the public fields

through the properties. The properties can control the access to internal

fields through the get and set functions, you can choose to implement any

one or both the functions in order to control the access based on the

requirement.

Apart from the controlled access and security the properties also offer

another major advantage over the public field like, say if any exception is

raised when setting any particular field the field may be left in the

invalid state, where as if any exception occurs while accessing the field

through the property the old value is retained automatically there by

laving the encapsulated field in the valid state even though the exception

occurs.
__________________
A.Rajesh Khanna
Reply With Quote