PHP*_*PHP 3 macos powershell class
我试图在类中的函数中运行进程,但它什么也不做。看起来编译器忽略了它,但是,在类之外它完美地工作。
<# Works here #>
#Get-Process
class Test
{
[void]TestFunction()
{
<# DOES NOT WORK HERE #>
Get-Process
}
}
[Test]$object = [Test]::new()
$object.TestFunction()
<# Works here #>
#Get-Process
Run Code Online (Sandbox Code Playgroud)
PS 我在 macOS 上使用 PowerShell 和 VS Code
它什么都不做,因为你说什么都不做。
[void]TestFunction()
Run Code Online (Sandbox Code Playgroud)
void 指示抑制任何输出对象。这是工作示例:
class Test
{
[System.Diagnostics.Process[]]TestFunction()
{
return Get-Process
}
}
Run Code Online (Sandbox Code Playgroud)
并且无需将结果存储在中间变量中。
| 归档时间: |
|
| 查看次数: |
75 次 |
| 最近记录: |