Information.TypeName(Object) Information.TypeName(Object) Information.TypeName(Object) Information.TypeName(Object) Method

定義

傳回 String 值,其中包含與變數有關的資料類型資訊。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);
static member TypeName : obj -> string
Public Function TypeName (VarName As Object) As String

參數

VarName
Object Object Object Object

必要項。Required. Object 變數。Object variable. 如果 Option StrictOff,您可以傳遞任何資料型別的變數,但是結構除外。If Option Strict is Off, you can pass a variable of any data type except a structure.

傳回

傳回 String 值,其中包含與變數有關的資料類型資訊。Returns a String value containing data-type information about a variable.

範例

下列範例會使用TypeName函數來傳回有關數個變數的資料類型資訊。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()".

備註

下表顯示TypeName針對不同String內容VarName所傳回的值。The following table shows the String values returned by TypeName for different contents of VarName.

VarName編制VarName contents 傳回的字串String returned
16位TrueFalse實值型別16-bit True or False value type True"Boolean"
8位二進位數值型別8-bit binary value type "Byte"
16位字元數值型別16-bit character value type Char"Char"
64位日期和時間值類型64-bit date and time value type 日期"Date"
表示遺失或不存在資料的參考型別Reference type indicating missing or nonexistent data "DBNull""DBNull"
128-bit 固定點數數值型別128-bit fixed-point numeric value type "Decimal"
64位浮點數數值型別64-bit floating-point numeric value type "Double"
32位整數數值型別32-bit integer value type 介於"Integer"
指向特製化物件的參考型別Reference type pointing to an unspecialized object 目標"Object"
指向從類別objectclass建立之特製化物件的參考型別Reference type pointing to a specialized object created from class objectclass objectclass"objectclass"
64位整數數值型別64-bit integer value type 前提"Long"
目前未指派物件的參考型別Reference type with no object currently assigned to it 這裡"Nothing"
8位帶正負號的整數數值型別8-bit signed integer value type SByte"SByte"
16位整數數值型別16-bit integer value type 短缺"Short"
32位浮點數數值型別32-bit floating-point numeric value type 單機"Single"
指向16位字元字串的參考型別Reference type pointing to a string of 16-bit characters 字串"String"
32-bit 不帶正負號整數數值型別32-bit unsigned integer value type UInteger"UInteger"
64-bit 不帶正負號整數數值型別64-bit unsigned integer value type ULong"ULong"
16位不帶正負號整數數值型別16-bit unsigned integer value type UShort"UShort"

如果VarName是陣列, 則傳回的字串可以是上表中附加空括弧的任何一個字串。If VarName is an array, the returned string can be any one of the strings in the preceding table with empty parentheses appended. 例如, 如果指向VarName整數陣列, TypeName則會傳回 "Integer ()"。For example, if VarName points to an array of integers, TypeName returns "Integer()".

TypeName傳回參考型別的名稱 (例如類別) 時, 它只會傳回名稱本身, 而不會傳回限定名稱。When TypeName returns the name of a reference type such as a class, it returns only the name itself, not the qualified name. 例如, 如果指向VarName類別System.Drawing.Printing.PaperSource的物件, TypeName則會傳回 "PaperSource"。For example, if VarName points to an object of class System.Drawing.Printing.PaperSource, TypeName returns "PaperSource". 請注意, 如果變數宣告為特定類別類型, 但未指派物件, TypeName則會傳回「無」。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".

適用於

另請參閱