0
的功能,我預計今年的代碼運行Foo()
:在PowerShell中運行變量名
function Foo {
[Console]::WriteLine("Foo")
}
$Bar = [Console]::ReadLine()
# If $Bar is Foo then it should do the function "Foo", right?
$Bar()
的功能,我預計今年的代碼運行Foo()
:在PowerShell中運行變量名
function Foo {
[Console]::WriteLine("Foo")
}
$Bar = [Console]::ReadLine()
# If $Bar is Foo then it should do the function "Foo", right?
$Bar()
功能遵循verb-noun
模式,大多數.NET方法有一個PowerShell相當於稱爲cmdlet
所以你的函數可以是:
function Get-Foo {
#[Console]::WriteLine('Foo')
Write-Host 'This is foo'
}
Get-Foo
或
$Bar = Get-Foo
$Bar
Get-Command
和Get-Help
是你的朋友,試試吧。
沒有完全按照我想要的去做,我認爲這是我的錯,因爲它太寬泛,我固定它是我真正想要做的。 –
你用'[console] :: readline()的用戶輸入提供$ bar,它總是一個字符串.... foo'function'和foo'string'不是一回事 – Kiran