Export (0) Print
Expand All

Information.TypeName Method

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

Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public static string TypeName(
	Object VarName
)

Parameters

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

Return Value

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

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".

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()".


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft