Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare a variable and its type is Boolean in PowerShell? [duplicate]

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 ?

like image 613
HushChen Avatar asked Feb 16 '19 08:02

HushChen


1 Answers

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
like image 137
Akash Pal Avatar answered Oct 04 '22 21:10

Akash Pal