您现在的位置是:网站首页> 编程资料编程资料
Windows Powershell 复制数组_PowerShell_
2023-05-26
320人已围观
简介 Windows Powershell 复制数组_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_
- PowerShell小技巧之同时使用可选强制参数_PowerShell_
- PowerShell小技巧之添加远程防火墙规则_PowerShell_
- PowerShell小技巧之配置机器的静态IP_PowerShell_
- PowerShell小技巧之启动远程桌面连接_PowerShell_
- Windows Powershell 创建数组_PowerShell_
- Windows Powershell 命令返回数组_PowerShell_
- Windows Powershell 变量的幕后管理_PowerShell_
- Windows Powershell 变量的类型和强类型_PowerShell_
- Windows Powershell 变量的作用域_PowerShell_
