问题
When I study PowerShell scripting language, I knew the data type is auto-assignment. If I want to declare a Boolean type variable, how can I do it?
Example: $myvariable = "string" or $myvalue = 3.14159 $myboolean ?
回答1:
Boolean values (which can be either 1 or 0) are defined in PowerShell using the .Net System.Boolean type (the short from of which is [bool]). For example, the following command assigns true to a variable of boolean type:
PS C:\Users\Administrator> [bool] $myval = 1
PS C:\Users\Administrator> $myval.gettype().fullname
System.Boolean
When working with boolean variables, the pre-defined
$true
and
$false
variables may also be used:
PS C:\Users\Administrator> [bool] $myval = $false
PS C:\Users\Administrator> $myval
False
来源:https://stackoverflow.com/questions/54721256/how-to-declare-a-variable-and-its-type-is-boolean-in-powershell