您现在的位置是:网站首页> 编程资料编程资料
PowerShell小技巧之True和False的类型转换_PowerShell_
2023-05-26
326人已围观
简介 PowerShell小技巧之True和False的类型转换_PowerShell_
在条件判断时,离不开$True和$False,将其它类型转换成Bool类型时,有几点需要留意:
其它类型转换成布尔类型
PS> 0,1,-1,'0','1','true','false',$null | foreach { [bool]$_ } False True True True True True True False 总结:只有整数0和Null才能转换成False,其它都会被强制类型转换成True
布尔类型转换成字符串
复制代码 代码如下:
PS> $true,$false | foreach { $_.ToString() } True False
这个应当没什么悬念。
布尔类型转换成整数
复制代码 代码如下:
PS> $true,$false | foreach { [int] $_ } 1 0
1和0分别代表true和false也可以理解。
您可能感兴趣的文章:
相关内容
- PowerShell小技巧之观察UNC路径_PowerShell_
- PowerShell小技巧之使用Verb打开程序_PowerShell_
- PowerShell小技巧之从函数中返回多个值_PowerShell_
- PowerShell小技巧之使用New-Module命令动态创建对象_PowerShell_
- PowerShell小技巧之使用Hotmail账号发送邮件_PowerShell_
- Powershell小技巧之设置IE代理_PowerShell_
- Powershell小技巧之找出最大最小值_PowerShell_
- Powershell小技巧之屏蔽输出结果_PowerShell_
- Powershell小技巧之删除不规则字符_PowerShell_
- Windows Powershell 复制数组_PowerShell_
