Cod*_*ick 8 c# vb.net powershell short-circuiting
Technet 关于Windows PowerShell 4.0的about_Logical_Operators声明如下:
Operator Description Example
-------- ------------------------------ ------------------------
-or Logical or. TRUE when either (1 -eq 1) -or (1 -eq 2)
or both statements are TRUE. True
-xor Logical exclusive or. TRUE (1 -eq 1) -xor (2 -eq 2)
only when one of the statements False
is TRUE and the other is FALSE.
Run Code Online (Sandbox Code Playgroud)
似乎都没有进行短路评估.
如何在Windows Powershell 4.0中模仿C# ||或VB ?OrElse
Kei*_*ill 17
一组简单的测试用例表明短路工作:
PS C:\> 1 -eq 0 -or $(Write-Host 'foo')
foo
False
PS C:\> 1 -eq 1 -or $(Write-Host 'foo')
True
PS C:\> 1 -eq 1 -and $(Write-Host 'foo')
foo
False
PS C:\> 1 -eq 0 -and $(Write-Host 'foo')
False
Run Code Online (Sandbox Code Playgroud)