Windows Powershell 复制数组 Windows Powershell 复制数组

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Windows Powershell 复制数组 Windows Powershell 复制数组

  2021-03-19 我要评论
想了解Windows Powershell 复制数组的相关内容吗,在本文为您仔细讲解Windows Powershell 复制数组 的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们