Information.IsNumeric(Object) 方法
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回 Boolean
值,指出運算式是否可以評估為數字。
public:
static bool IsNumeric(System::Object ^ Expression);
public static bool IsNumeric (object? Expression);
public static bool IsNumeric (object Expression);
static member IsNumeric : obj -> bool
Public Function IsNumeric (Expression As Object) As Boolean
- Expression
- Object
必要。
Object
運算式。
傳回 Boolean
值,指出運算式是否可以評估為數字。
下列範例會 IsNumeric
使用函式來判斷變數的內容是否可以評估為數位。
Dim testVar As Object
Dim numericCheck As Boolean
testVar = "53"
' The following call to IsNumeric returns True.
numericCheck = IsNumeric(testVar)
testVar = "459.95"
' The following call to IsNumeric returns True.
numericCheck = IsNumeric(testVar)
testVar = "45 Help"
' The following call to IsNumeric returns False.
numericCheck = IsNumeric(testVar)
IsNumeric
True
如果的Expression
資料類型為Boolean
、Byte
、Decimal
、Double
、Integer
、 Single
UInteger
Short
SByte
Long
ULong
或 UShort
, 則會傳回 。 如果 是 、, 或 Object
可以成功轉換成數位,它也會傳回 True
。 String
Char
Expression
Expression
可以包含非數值字元。
IsNumeric
True
如果 Expression
包含有效十六進位或八進位數位的字串,則會傳回 。
IsNumeric
如果 包含以 + 或 - 字元開頭的有效數值表示式,或包含逗號,也會傳回 True
Expression
。
IsNumeric
False
如果 Expression
是資料型態 Date
,則會傳回 。 如果 為 、String
、 或 Object
,則傳回False
無法成功轉換為數位Char
的 。Expression
產品 | 版本 |
---|---|
.NET | Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |