Explains about how we can have different access modifier for getter and setter in a property.
We normally specify the access modifier of a property during its declaration before the return type.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// getter and setter are public public string EmployeeCode { get { return _employeeCode; } set { _employeeCode = value; } } |
This access modifier will be applicable to both getter and setter of the property by default. However there is an interesting fact in .net, we can have different access modifier for both getter and setter. To specify that
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// getter is publilc and setter is internal public string EmployeeCode { get { return _employeeCode; } internal set { _employeeCode = value; } } |
There is one thing to keep remember is that you cannot specify access modifier for both getter and setter at same time. The other will always take the default from property. However this doesn’t matter to us as we can achieve any combination from available flexibility.