簡而言之,我正在嘗試-
$animal = "cat", "dog", "rabbit"
$animal -contains "dog" # -----> Getting true, which is working!
但是,當我嘗試檢查多個值時 -
$animal -contains "dog" -and "bat" # --> still getting a "True" response.
如何使用包含運算子檢查多個值?
uj5u.com熱心網友回復:
布爾運算式的作業方式略有不同。你需要這個:
$animal -contains "dog" -and $animal -contains "bat"
您也可以將“dog”和“bat”放入它們自己的陣列中,然后回圈遍歷陣列。
uj5u.com熱心網友回復:
為了補充Joel Coehoorn 的有用答案,您可以使用Class中的IsSupersetOf(IEnumerable<T>)Method。HashSet<T>
$animal = [System.Collections.Generic.HashSet[string]]::new(
[string[]] ('cat', 'dog', 'rabbit'),
[System.StringComparer]::OrdinalIgnoreCase
)
$animal.IsSupersetOf([string[]] ('dog', 'bat')) # => False
$animal.IsSupersetOf([string[]] ('dog', 'cat')) # => True
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/521961.html
標籤:电源外壳
