您现在的位置是:网站首页> 编程资料编程资料
PowerShell数组结合switch语句产生的奇特效果介绍_PowerShell_
2023-05-26
337人已围观
简介 PowerShell数组结合switch语句产生的奇特效果介绍_PowerShell_
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
five
four
two
three
five
two
five
这是一个很新奇的效果,先记录在这里,后面有需要再来深度挖掘它。
您可能感兴趣的文章:
相关内容
- PowerShell查找数组内容、搜索数组、查询数组的方法_PowerShell_
- PowerShell创建Byte数组例子_PowerShell_
- PowerShell中使用ArrayList实现数组插入、删除、添加例子_PowerShell_
- PowerShell中使用Get-Alias命令获取cmdlet别名例子_PowerShell_
- PowerShell脚本写的文件.ps1文件介绍_PowerShell_
- PowerShell中使用Get-Date获取日期时间并格式化输出的例子_PowerShell_
- PowerShell单行注释、多行注释、块注释的方法_PowerShell_
- PowerShell判断某天是星期几的方法_PowerShell_
- PowerShell中计算时间差的方法_PowerShell_
- PowerShell获取当前进程PID的小技巧_PowerShell_
