源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Windows Powershell强类型数组

  • 时间:2021-08-31 21:50 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Windows 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
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部