How to: Declare a Property with Mixed Access Levels (Visual Basic)
Updated: July 20, 2015
For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.
If you want the
Set procedures on a property to have different access levels, you can use the more permissive level in the
Property statement and the more restrictive level in either the
Set statement. You use mixed access levels on a property when you want certain parts of the code to be able to get the property's value, and certain other parts of the code to be able to change the value.
For more information on access levels, see Access Levels in Visual Basic.
Declare the property in the normal way, and specify the less restrictive access level (such as
Public) in the
Declare either the
Setprocedure specifying the more restrictive access level (such as
Do not specify an access level on the other property procedure. It assumes the access level declared in the
Propertystatement. You can restrict access on only one of the property procedures.
Public Class employee Private salaryValue As Double Protected Property salary() As Double Get Return salaryValue End Get Private Set(ByVal value As Double) salaryValue = value End Set End Property End Class
In the preceding example, the
Getprocedure has the same
Protectedaccess as the property itself, while the
Privateaccess. A class derived from
employeecan read the
salaryvalue, but only the
employeeclass can set it.
Procedure Parameters and Arguments
Differences Between Properties and Variables in Visual Basic
How to: Create a Property
How to: Call a Property Procedure
How to: Declare and Call a Default Property in Visual Basic
How to: Put a Value in a Property
How to: Get a Value from a Property