How to: Access Shared and Nonshared Members of an Object

Once an object is created, you can access its fields, properties, methods, and events through the object's variable. If the member is Shared (Visual Basic), you do not need to create an object to access it.

Accessing Nonshared Members

To access a nonshared member of an object

  1. Make sure the object has been created from its class and assigned to an object variable.

    Dim secondForm As New System.Windows.Forms.Form
    
  2. In the statement that accesses the member, follow the object variable name with the member-access operator (.) and then the member name.

    secondForm.Show()
    

Accessing Shared Members

To access a shared member of an object

  • Follow the class name with the member-access operator (.) and then the member name. You should always access a Shared member of the object directly through the class name.

    MsgBox("This computer is called " & Environment.MachineName)
    
  • If you have already created an object from the class, you can alternatively access a Shared member through the object's variable.

See Also

Tasks

How to: Create an Object

How to: Reuse a Working Component

How to: Define a Class That Uses Members of an Existing Class

How to: Access Members of an Object

Concepts

Object Members