Skip to content

Latest commit

 

History

History
44 lines (34 loc) · 2.8 KB

how-to-declare-a-property-with-mixed-access-levels.md

File metadata and controls

44 lines (34 loc) · 2.8 KB
description title ms.date helpviewer_keywords ms.assetid
Learn more about: How to: Declare a Property with Mixed Access Levels (Visual Basic)
How to: Declare a Property with Mixed Access Levels
07/20/2015
access levels [Visual Basic], properties
procedures [Visual Basic], defining
Visual Basic code, procedures
mixed access levels
Visual Basic code, properties
properties [Visual Basic], access levels
Property statement [Visual Basic], declaring mixed access levels
fdbb2d97-279a-4956-b26c-cbdfbc34915a

How to: Declare a Property with Mixed Access Levels (Visual Basic)

If you want the Get and 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 Get or 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.

To declare a property with mixed access levels

  1. Declare the property in the normal way, and specify the less restrictive access level (such as Public) in the Property statement.

  2. Declare either the Get or the Set procedure specifying the more restrictive access level (such as Friend).

  3. Do not specify an access level on the other property procedure. It assumes the access level declared in the Property statement. You can restrict access on only one of the property procedures.

    [!code-vbVbVbcnProcedures#10]

    In the preceding example, the Get procedure has the same Protected access as the property itself, while the Set procedure has Private access. A class derived from employee can read the salary value, but only the employee class can set it.

See also