您现在的位置是:网站首页> 编程资料编程资料
Windows Powershell强类型数组_PowerShell_
2023-05-26
529人已围观
简介 Windows Powershell强类型数组_PowerShell_
Powershell数组一般具有多态性,如果你不指定元素的具体类型,解释器会自动选择合适的类型存储每个元素。如果要统一限制所有元素的类型,可是使用类型名和一对方括号作为数组变量的类型。这样每当赋值时,会自动类型检查。如果目标数据类型不能转换成功,就会抛出一个异常。
PS C:Powershell> [int[]] $nums=@() PS C:Powershell> $nums+=2012 PS C:Powershell> $nums+=12.3 PS C:Powershell> $nums+="999" PS C:Powershell> $nums+="can not convert" Cannot convert value "can not convert" to type "System.Int32". Error: "Input string was not in a correct format." At line:1 char:6 + $nums <<<< +="can not convert" + CategoryInfo : MetadataError: (:) [], ArgumentTransformationMetadataException + FullyQualifiedErrorId : RuntimeException
您可能感兴趣的文章:
相关内容
- Powershell小技巧之获取当前的时间并转换为时辰_PowerShell_
- Powershell小技巧之判断是否包涵大小写_PowerShell_
- PowerShell小技巧之调用CloudFlare的SDK查询网站统计信息_PowerShell_
- PowerShell小技巧实现IE Web自动化_PowerShell_
- Windows Azure VM上配置FTP服务器_PowerShell_
- Powershell小技巧之查看安装的.Net framework版本信息_PowerShell_
- Powershell小技巧之非相同域或信任域也能远程_PowerShell_
- Powershell小技巧之从文件获取系统日志_PowerShell_
- Powershell小技巧之使用WMI工具_PowerShell_
- Powershell小技巧之创建一个新对象_PowerShell_
