是否有更简洁/惯用的方式来完成以下操作?我对逻辑中的双重否定印象不深。
e.g。对于集合中的所有项目,IsPass
为true
$data = ,@{'IsPass' = $true}, @{'IsPass' = $true}, @{'IsPass' = $true}
if(!$data.IsPass.Contains($false))
{
Write-Host 'foo'
}
答案 0 :(得分:0)
你的方法怎么了?我能想到这样的事情:
$data = @{'IsPass' = $true}, @{'IsPass' = $true}, @{'IsPass' = $true}
foreach ($item in $data)
{
if ($item['IsPass'] -ne $true)
{
Write-Host 'foo'
}
}
或者这个:
$data = @{'IsPass' = $true}, @{'IsPass' = $false}, @{'IsPass' = $true}
$data.IsPass | Where-Object {$_ -ne $true}