Deep-copy an array

后端 未结 2 862
名媛妹妹
名媛妹妹 2020-12-21 06:15

I\'ve been banging my head against the wall on this one.
I know that if I create an Array in Powershell, then copy the array, it\'ll copy it as a reference type not a va

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-21 06:44

    Technically $d = $c is not any sort of array copy (of reference or value). It's just stashing a reference to the array $c refers to, into $d. I think you only need to grab the array of processes once and then call the Refresh method. You'll have to check the Exited property first to make sure the associated process is still running. Of course, this won't help you if you're interested in any new process that start up. In that case, grab a snapshot of processes at different times, weed out all but the intersection of processes between the two arrays (by process Id) and then compute the differences in their property values - again based on process Id. Take make this easier, you might want to put each snapshot in a hashtable keyed off the process Id.

提交回复
热议问题