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