如果我调用该函数没有默认值工作功能命名参数问题默认
当我打电话与名为参数的函数,我离开他们的一个空白,我得到一个错误的任何参数...任何方式来纠正这个?
下面是函数
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.