PowerShell數組與switch語句,PowerShell中數組可以與switch語句結合,產生意想不到的效果。
PowerShell中數組可以與switch語句結合,產生意想不到的效果。
先看看例子:
復制代碼 代碼如下:
$myArray = 1,5,4,2,3,5,2,5
Switch ( $myArray ) {
1 { 'one' }
2 { 'two' }
3 { 'three' }
4 { 'four' }
5 { 'five' }
}
數組中的所有元素都是在1,2,3,4,5這個范圍的。通過一個switch語句,把每個數字做一個翻譯。
在switch之后會自動輸出,所以,最終的結果就成了:
復制代碼 代碼如下:
one
five
four
two
three
five
two
five
這是一個很新奇的效果,先記錄在這里,后面有需要再來深度挖掘它。
您可能感興趣的文章:- 探索PowerShell (八) 數組、哈希表(附:復制粘貼技巧)
- Powershell創建數組正確、更快的方法
- PowerShell查找數組內容、搜索數組、查詢數組的方法
- PowerShell中的強類型數組介紹
- PowerShell數組的一些操作技巧
- PowerShell數組操作簡明教程
- Windows Powershell 命令返回數組
- Windows Powershell 創建數組