function AreEqual-Arrays { [CmdletBinding()] param ( [parameter(Mandatory=$true, Position=0)] [array] $a1, [parameter(Mandatory=$true, Position=1)] [array] $a2 ) if ($a1.Rank -ne $a2.Rank) { return $false } if ([System.Object]::ReferenceEquals($a1, $a2)) { return $true } for ($r = 0; $r -lt $a1.Rank; $r++) { if ($a1.GetLength($r) -ne $a2.GetLength($r)) { return $false } } $enum1 = $a1.GetEnumerator() $enum2 = $a2.GetEnumerator() while ($enum1.MoveNext() -and $enum2.MoveNext()) { if ($enum1.Current -ne $enum2.Current) { return $false } } return $true }
Poniższe wywołania zwracają true:
AreEqual-Arrays -a1 @(1) -a2 @(1) AreEqual-Arrays -a1 @(1,"a") -a2 @(1,"A") AreEqual-Arrays -a1 @(1,-123) -a2 @("1","-123") AreEqual-Arrays -a1 @(12,34) -a2 12,34
Brak komentarzy:
Prześlij komentarz