我有两段代码:
# code 1:
[type]$t1 = [switch]
# all is ok, code works as expected
#code 2:
function test ([type]$t2) { }
test -t2 [switch]
# here we get error. can't convert from string to system.type
我知道,我可以写:test -t2 "System.Management.Automation.SwitchParameter"
,但它很丑!!为什么我可以将 [switch] 设置为 [type] 变量,但不能将其传递给函数?