Επεξεργασία

Κοινή χρήση μέσω


Information.TypeName(Object) Method

Definition

Returns a String value containing data-type information about a variable.

public:
 static System::String ^ TypeName(System::Object ^ VarName);
public static string TypeName (object? VarName);
public static string TypeName (object VarName);
static member TypeName : obj -> string
Public Function TypeName (VarName As Object) As String

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 a String value containing data-type information about a variable.

Examples

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

Dim testType As String
Dim strVar As String = "String for testing"
Dim decVar As Decimal
Dim intVar, arrayVar(5) As Integer
testType = TypeName(strVar)
' The preceding call returns "String".
testType = TypeName(decVar)
' The preceding call returns "Decimal".
testType = TypeName(intVar)
' The preceding call returns "Integer".
testType = TypeName(arrayVar)
' The preceding call returns "Integer()".

Remarks

The following table shows the String values returned by TypeName for different contents of VarName.

VarName contents String returned
16-bit True or False value type "Boolean"
8-bit binary value type "Byte"
16-bit character value type "Char"
64-bit date and time value type "Date"
Reference type indicating missing or nonexistent data "DBNull"
128-bit fixed-point numeric value type "Decimal"
64-bit floating-point numeric value type "Double"
32-bit integer value type "Integer"
Reference type pointing to an unspecialized object "Object"
Reference type pointing to a specialized object created from class objectclass "objectclass"
64-bit integer value type "Long"
Reference type with no object currently assigned to it "Nothing"
8-bit signed integer value type "SByte"
16-bit integer value type "Short"
32-bit floating-point numeric value type "Single"
Reference type pointing to a string of 16-bit characters "String"
32-bit unsigned integer value type "UInteger"
64-bit unsigned integer value type "ULong"
16-bit unsigned integer value type "UShort"

If VarName is an array, the returned string can be any one of the strings in the preceding table with empty parentheses appended. For example, if VarName points to an array of integers, TypeName returns "Integer()".

When TypeName returns the name of a reference type such as a class, it returns only the name itself, not the qualified name. For example, if VarName points to an object of class System.Drawing.Printing.PaperSource, TypeName returns "PaperSource". Note that if the variable is declared to be of a certain class type but does not have an object assigned to it, TypeName returns "Nothing".

Applies to

See also