Property Accessor Accessibility
Normally in our life, we will allow others to review about properties. But wont allow all of them to set the property or change its nature. Likewise, now in C# property also we can set the accessibility level to the get and set accessors.
Syntax:
public data_type property_name
{
get { return variable_name;}
protected set { variable_name = value;}
}
Example:
public string empname
{
get
{
return empname;
}
protected set
{
empname = value;
}
}
Benefit:
By implementing this logic, only classes deriving from this class can set the property values not by others.
:)
No comments:
Post a Comment