手机
当前位置:查字典教程网 >脚本专栏 >PowerShell >Windows Powershell 复制数组
Windows Powershell 复制数组
摘要:数组属于引用类型,使用默认的的赋值运算符在两个变量之间赋值只是复制了一个引用,两个变量共享同一份数据。这样的模式有一个弊病如果其中一个改变也...

数组属于引用类型,使用默认的的赋值运算符在两个变量之间赋值只是复制了一个引用,两个变量共享同一份数据。这样的模式有一个弊病如果其中一个改变也会株连到另外一个。所以复制数组最好使用Clone()方法,除非有特殊需求。

PS C:Powershell> $chs=@("A","B","C") PS C:Powershell> $chsBak=$chs PS C:Powershell> $chsBak[1]="H" PS C:Powershell> $chs A H C PS C:Powershell> $chs.Equals($chsBak) True PS C:Powershell> $chsNew=$chs.Clone() PS C:Powershell> $chsNew[1]="Good" PS C:Powershell> $chs.Equals($chsNew) False PS C:Powershell> $chs A H C

【Windows Powershell 复制数组】相关文章:

PowerShell函数用Hash表传参实例

PowerShell数组操作简明教程

Windows Powershell For 循环

PowerShell中判断闰年的方法

Windows Powershell 快捷键介绍

PowerShell函数指定返回值类型实例

Windows Powershell 定义函数

Windows Powershell 创建数组

Windows Powershell 定义变量

PowerShell 入门基础教程

精品推荐
分类导航