Megosztás a következőn keresztül:


How to: Declare an Object Variable and Assign an Object to It in Visual Basic

You declare a variable of the Object Data Type by specifying As Object in a Dim Statement (Visual Basic). You assign an object to such a variable by placing the object after the equal sign (=) in an assignment statement or initialization clause.

Example

The following example declares an Object variable and assigns the current instance to it.

Dim thisObject As Object
thisObject = "This is an Object"

You can combine the declaration and assignment by initializing the variable as part of its declaration. The following example is equivalent to the preceding example.

Dim thisObject As Object = "This is an Object"

Compiling the Code

This example requires:

  • A reference to the System namespace.

  • A class, structure, or module in which to put the Dim statement.

  • A procedure in which to put the assignment statement.

See Also

Reference

Object Data Type

Dim Statement (Visual Basic)

Option Strict Statement

Concepts

Variable Declaration in Visual Basic

Object Variables in Visual Basic

Object Variable Declaration (Visual Basic)

Local Type Inference (Visual Basic)