public int PropertyName {get;set}
is an
auto implemented property
, which will be expanded by the
compiler
and
the back end store
will be created like
private int propertyName
public int PropertyName {
get { return propertyName; }
set { propertyName = value;}
}
So, an
auto implemented property
is a
normal property
for the executing code and its only a shortcut to the programmer
when no other actions like validations
are required to be performed
within the getter and setter
of the property.
Now, the difference between a variable and a property is that the value of the variable is
directly set and retrieved
, whereas in case of
Property it is set in setter and retrieved in getter which permits to perform extra operations
like validations.
The .NET Framework design guideline
does not recommend the usage of public variable
.
Further, in .NET
data binding cannot be done with variable
but the data binding can be done
with property
.