如果我調用該函數沒有默認值工作功能命名參數問題默認
當我打電話與名爲參數的函數,我離開他們的一個空白,我得到一個錯誤的任何參數...任何方式來糾正這個?
下面是函數
function foo {
Param(
[string]$a,
[string]$b = "bar",
[bool]$c = $false
)
Write-Host "a:", $a, "; b:", $b, "; c:", $c
}
foo "hello"
回報a: hello ; b: bar ; c: False
。
foo -a test -b test -c $true
返回a: test ; b: test ; c: True
。
foo -a test -b test -c
拋出一個錯誤:當你省略該參數完全
foo : Missing an argument for parameter 'c'. Specify a parameter of type 'System.Boolean' and try again.