2
爲什麼參數輸入有兩種不同的格式?除了個人品味之外,還有其他好處嗎?通過「function myfunc(<param here>)」在函數內部使用「param(<params here))有技術優勢嗎?
例如,我使用的這個,因爲這是我第一次看到閱讀文檔中關於Powershell的
function MyAwesomeFunction
(
[parameter(Mandatory=$Whatever)]
[string]
$MyAwesomeVariable = MyAwesomeDefaultValue
)
{MyAwesome stuff to do}
但看其中的參數是由這樣
function MyAwesomeFunction
{
param(
[parameter(Mandatory=$Whatever)]
[string]
$MyAwesomeVariable = MyAwesomeDefaultValue
)
MyAwesome stuff to do
}
用戶所做的例子,當有情況
另外,param()語句對於帶參數的腳本和scriptblocks是必需的。 – 2015-02-11 13:06:24