在 PowerShell 中,如何测试变量是否包含数值?
目前,我正在尝试这样做,但它似乎总是返回false
。
add-type -Language CSharpVersion3 @'
public class Helpers {
public static bool IsNumeric(object o) {
return o is byte || o is short || o is int || o is long
|| o is sbyte || o is ushort || o is uint || o is ulong
|| o is float || o is double || o is decimal
;
}
}
'@
filter isNumeric($InputObject) {
[Helpers]::IsNumeric($InputObject)
}
PS> 1 | isNumeric
False