Uređivanje

Dijeli putem


Information.VarType(Object) Method

Definition

Returns an Integer value containing the data type classification of a variable.

public:
 static Microsoft::VisualBasic::VariantType VarType(System::Object ^ VarName);
public static Microsoft.VisualBasic.VariantType VarType (object? VarName);
public static Microsoft.VisualBasic.VariantType VarType (object VarName);
static member VarType : obj -> Microsoft.VisualBasic.VariantType
Public Function VarType (VarName As Object) As VariantType

Parameters

VarName
Object

Required. Object variable. If Option Strict is Off, you can pass a variable of any data type except a structure.

Returns

Returns an Integer value containing the data type classification of a variable.

Examples

The following example uses the VarType function to return data type classification information about several variables.

Dim testString As String = "String for testing"
Dim testObject As New Object
Dim testNumber, testArray(5) As Integer
Dim testVarType As VariantType
testVarType = VarType(testVarType)
' Returns VariantType.Integer.
testVarType = VarType(testString)
' Returns VariantType.String.
testVarType = VarType(testObject)
' Returns VariantType.Object.
testVarType = VarType(testNumber)
' Returns VariantType.Integer.
testVarType = VarType(testArray)
' Returns the bitwise OR of VariantType.Array and VariantType.Integer.

Remarks

The integer value returned by VarType is a member of the VariantType.

The following table shows the values returned by VarType for special cases of VarName.

Data type represented by VarName Value returned by VarType
Nothing VariantType.Object
DBNull VariantType.Null
Enumeration Underlying data type (SByte, Byte, Short, UShort, Integer, UInteger, Long, or ULong)
Array Bitwise OR of array element type and VariantType.Array
Array of arrays Bitwise OR of VariantType.Object and VariantType.Array
Structure (System.ValueType) VariantType.UserDefinedType
Exception VariantType.Error
Unknown VariantType.Object

Applies to

See also