PowerShell the type conversion of true and false of the tip _powershell

Source: Internet
Author: User
Tags true true

When the condition is judged, inseparable from $true and $false, when converting other types to bool type, there are several points to be aware of:

Other types convert to Boolean type

ps> 0,1,-1, ' 0 ', ' 1 ', ' true ', ' false ', $null | foreach {[Bool]$_} False True True to True True True
false

Summary: only integers 0 and null can be converted to false, and all others are cast to true

Convert Boolean type to string

Copy Code code as follows:
Ps> $true, $false | foreach {$_. ToString ()} True False

This should be no suspense.

Convert Boolean type to Integer

Copy Code code as follows:
Ps> $true, $false | foreach {[int] $_} 1 0

It is understandable that 1 and 0 represent true and false respectively.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.