您现在的位置是:网站首页> 编程资料编程资料
Windows Powershell 创建数组_PowerShell_
2023-05-26
295人已围观
简介 Windows Powershell 创建数组_PowerShell_
在Powershell中创建数组可以使用逗号。
PS C:Powershell> $nums=2,0,1,2 PS C:Powershell> $nums 2 0 1 2
对于连续的数字数组可以使用一个更快捷的方法
PS C:Powershell> $nums=1..5 PS C:Powershell> $nums 1 2 3 4 5
数组的多态
象变量一样如果数组中元素的类型为弱类型,默认可以存储不同类型的值。
PS C:Powershell> $array=1,"2012世界末日",([System.Guid]::NewGuid()),(get-date) PS C:Powershell> $array 1 2012世界末日 Guid ---- 06a88783-a181-4511-9e41-2780ecbd7924 DisplayHint : DateTime Date : 2011/12/9 0:00:00 Day : 9 DayOfWeek : Friday DayOfYear : 343 Hour : 14 Kind : Local Millisecond : 910 Minute : 15 Month : 12 Second : 45 Ticks : 634590369459101334 TimeOfDay : 14:15:45.9101334 Year : 2011 DateTime : 2011年12月9日 14:15:45
空数组和单元素数组
空数组
PS C:Powershell> $a=@() PS C:Powershell> $a -is [array] True PS C:Powershell> $a.Count 0
1个元素的数组
PS C:Powershell> $a=,"moss" PS C:Powershell> $a -is [array] True PS C:Powershell> $a.Count 1
您可能感兴趣的文章:
相关内容
- Windows Powershell 命令返回数组_PowerShell_
- Windows Powershell 变量的幕后管理_PowerShell_
- Windows Powershell 变量的类型和强类型_PowerShell_
- Windows Powershell 变量的作用域_PowerShell_
- Windows Powershell 环境变量_PowerShell_
- Windows Powershell 自动化变量_PowerShell_
- Windows Powershell 定义变量_PowerShell_
- Powershell小技巧之使用Get-ChildItem得到指定扩展名文件_PowerShell_
- Powershell小技巧之通过EventLog查看近期电脑开机和关机时间_PowerShell_
- Powershell小技巧之复合筛选_PowerShell_
