相关疑难解决方法(0)

为什么"switch"类型参数的值传递给字符串参数?

测试代码(test.ps1):

Param(
    [string]$content = $null,
    [switch]$flag = $false
)
Write-Host $content
Run Code Online (Sandbox Code Playgroud)

输出:

PS C:\Users\powershell> .\test.ps1

PS C:\Users\powershell> .\test.ps1 -flag $true    
True
PS C:\Users\powershell> .\test.ps1 -flag $false
False
PS C:\Users\powershell> .\test.ps1 -flag $true -content "lalala"
lalala

无论我设置$content$null,或者""没有任何默认值,输出都是相同的.

那么为什么$content要从中获取价值$flag呢?

powershell parameter-passing

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

parameter-passing ×1

powershell ×1