测试代码(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呢?